Vba ошибка 2465

0 / 0 / 0

Регистрация: 03.04.2018

Сообщений: 90

1

17.10.2018, 13:05. Показов 4230. Ответов 4


Студворк — интернет-сервис помощи студентам

Уважаемые форумчане, добрый вечер! Не могу решить проблему, подскажите, если сталкивались ! В форме «Главная_Пенсионеры», хочу чтобы при нажатие на человека, о нем выдавалась информация! Но пишет ошибку 2465, так как не силен в VBA, прошу помочь советами! Принскрин и базу прилагаю! Пароль:12345!Заранее благодарю всех кто откликнулся!

Миниатюры

Ошибка 2465 access
 



0



mobile

Эксперт MS Access

26792 / 14471 / 3192

Регистрация: 28.04.2012

Сообщений: 15,782

17.10.2018, 13:20

2

Лучший ответ Сообщение было отмечено Alex_Barcelona как решение

Решение

Закомментируйте или удалите строку

Visual Basic
1
'    Me!txtUnderLine.SetFocus

в процедуре cmdOpen_Click() формы Главная_Пенсионеры

Вложения

Тип файла: rar Рабочий вариант.rar (4.55 Мб, 7 просмотров)



1



431 / 239 / 86

Регистрация: 09.04.2018

Сообщений: 1,023

17.10.2018, 13:22

3

Лучший ответ Сообщение было отмечено Alex_Barcelona как решение

Решение

Alex_Barcelona, пробуйте.

поздно.



1



0 / 0 / 0

Регистрация: 03.04.2018

Сообщений: 90

17.10.2018, 13:48

 [ТС]

4

Kiriver, mobile, спасибо большое за помощь!)

Добавлено через 17 минут
Ребят, а не подскажите еще как сделать чтоб не на кнопку «Открыть» можно было только открывать информацию, но и просто по двойному клику на человека?!



0



mobile

Эксперт MS Access

26792 / 14471 / 3192

Регистрация: 28.04.2012

Сообщений: 15,782

17.10.2018, 14:03

5

Лучший ответ Сообщение было отмечено Alex_Barcelona как решение

Решение

На событии двойного клика поля ФИО копируем тот же код, что и на кнопке

Visual Basic
1
2
3
4
5
Private Sub ФИО_DblClick(Cancel As Integer)
    s = "Код=" & Me!Код
    Me.Visible = False
    DoCmd.OpenForm "Пенсионеры", , , s
End Sub

Вложения

Тип файла: rar Рабочий вариант.rar (4.55 Мб, 5 просмотров)



1



  • Remove From My Forums
  • Question

  • I have a form that is bound to two tables (Students and ServicePlans). There is a command button on the form to create a report showing data from the current records (i.e., the current service plan for the current student).

    I had to make some structural changes in the tables.  Prior to those changes, everything worked perfectly. However, the report does not gets its data directly from the tables but from a query that assembles the neccesary data in one place— and that
    query is still working properly. The report also still works when opened directly (except of course it shows all records, which defeats its purpose)

    When I press the command button I get the error «Run-time error ‘2465’ …can’t find the field ‘|1’ referred to in your expression»

    the code behind the button is:

    Private Sub CmdPrint_Click()
    Dim strWhere As String
    If Me.Dirty Then    'Save any edits.
            Me.Dirty = False
        End If
    
    If Me.NewRecord Then 'Check there is a record to print
            MsgBox "Select a record to print"
        Else
            strWhere = "[PlanID] = " & Me.[PlanID]
            DoCmd.Close
            DoCmd.OpenReport "Contract", acViewPreview, , strWhere
        End If
        
    End Sub

    I’m guessing » field ‘|1’ » must refer to [PlanID], since there is no other field in the code. However, the field does exist both in the form and the report (and the query).

    1. Is there some problem with the way I have referenced [PlanID]?
    2. If so, is there some obvious reason why it worked before and not now?
    3. If not, is there some other explanation for this error message?

    (I checked the error message in the help menu and found nothing. A google search revealed numerous threads, but all seemed to be either unresolved or not connected with this situation)

    Thanks!


    —nick

Answers

  • Nick —

    OK…we know the issue is with that line of code.  The reason your ideas didn’t work is that at this point in the code, you are just trying to build the WHERE clause BEFORE you open the report.  So it makes sense that it was bombing on that code
    you mentioned.

    The next question I would ask is — is it bombing in the code where I build strWhere or when I am opening the report.  One way to troubleshoot this is to try

    strWhere = «PlanID = » & 6  (obviously 6 would have to be a valid planID…use something valid from your tables.

    If the code doesn’t work here, then you know the issue is in the report — when it tries to set the filter, it cannot. So you need to troubleshoot there.   You might try

    strWhere = «Reports!Contact!PlanID=» & me.PlanID or something like that.

    If the code does work here, then you know that the issue is that your form code cannot find Me.PlanID on the form.  In that case you need to check on the form and make sure there is still a text box or somethign called PlanID and that you can get to
    it (can you even do MsgBox me.[planID] and get a value?  What if you remove the brackets? I hate brackets and avoid at all cost).

    Last q if this doesn’t work — what kind of structure change did you make? Did it affect PlanID at all?

    Hope this is helpful. check back and let us know what you find!


    Joy Eakins CDD, Inc.

    • Proposed as answer by

      Tuesday, May 1, 2012 5:50 PM

    • Marked as answer by
      Nick Vittum
      Tuesday, May 1, 2012 6:55 PM

  • Exactly which line generates the error?
    the line strWhere =
    «[PlanID] = « &
    Me.[PlanID] generates the error.

    Since the error is on that line, the problem has nothing to do with the report, or the query the report is based on. It has to do with the form.

    Maybe there is no field or control on the form named PlanID, or there is a control named PlanID but not bound to the PlanID field, yet there is a PlanID field in the form’s recordsource, or PlanID appears more than once in the select statement of the recordsource.

    • Marked as answer by
      Nick Vittum
      Tuesday, May 1, 2012 6:54 PM

I keep getting a run time error ‘2465’ when running a query via VBA in Access.

Error: Microsoft Access can’t find the field ‘|1’ referred to in your expression

I can’t seem to find where this issue is occuring. Below is the VBA code that I’m currently using to requery a form.

Dim Test As String
Test = "*" & Combo161.Value

Dim strSQL As String
Dim strWhere As String
strWhere = (Chr(34) + Test + (Chr(34)))

'MsgBox (strWhere)

strSQL = "SELECT * FROM Test_Query WHERE TestID " & strWhere

'MsgBox (strSQL)
[Form_Test (subform)].RecordSource = strSQL
[Form_Test (subform)].Requery

The TestID had a field formatting of text, rather than a number. Does this matter at all?

Erik A's user avatar

Erik A

31.7k12 gold badges42 silver badges67 bronze badges

asked Feb 8, 2013 at 19:52

Muhnamana's user avatar

I have just fixed this error. I was referencing the subform’s source object, rather than its name given in the form properties.

answered Mar 9, 2016 at 23:20

rob's user avatar

0

I had the same error. What I missing was the double quotes around a string. This error is a bit misleading. Check the syntax etc and you will find the issue was related to comma or double quotes etc.

answered Sep 12, 2013 at 23:06

Tahir's user avatar

TahirTahir

212 bronze badges

Try:

Dim Test As String
Test = "*" & Combo161.Value

Dim strSQL As String
Dim strWhere As String
strWhere = (Chr(34) & Test & (Chr(34)))

'MsgBox (strWhere)

strSQL = "SELECT * FROM Test_Query WHERE TestID Like " & strWhere

'To test
'Debug.print strSQL

If this is a subform, then:

Me.[Form_Test (subform)].Form.RecordSource = strSQL
''Not needed when changing record source
''Me.[Form_Test (subform)].Form.Requery

You did not have an equals sign / Like and the concatenator in VBA is &, not +, using + can lead to problems with nulls, but in this case, I reckon the problen is the missing Like, that is

TestID Like "*something"

You can control the contents of a subform with a combo and a link field:

combo link

answered Feb 8, 2013 at 19:57

Fionnuala's user avatar

FionnualaFionnuala

90.4k7 gold badges114 silver badges152 bronze badges

8

I, too, had the same error and confirm it is a double double quote issue. You dim’ed

strWhere = (Chr(34) + Test + (Chr(34)))

which
produces ""*" & Combo161.Value"
resulting in the bad MS Access error message «can’t find …»

I would try variations on the double quotes. The following solved the issue for me:

"[Business Card ID]= " & Forms![Letterhead]![N/A] & " And [L2] Like '*Competency Questions'"

Note I used single quotes. I believe using single quotes versus double quotes is a mere issue of preference.

DecimalTurn's user avatar

DecimalTurn

3,3503 gold badges16 silver badges37 bronze badges

answered Jul 28 at 22:41

Jason T. Fleishman's user avatar

I am currently working on a form to update fields in my database. The button (cmdFind) is meant to find the record for the part # (entered into text box txtFindPart), and then populate the data into In1-52 and out1-52. When I run it I get Run-time Error 2465 Microsoft Access can not find the field '|1' referred to in your expression.

Private Sub cmdFind_Click()
    Dim i As Integer
    i = 1
    If IsNull(txtFindPart) = False Then
        If Me.Recordset.NoMatch Then
            MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
            Me!txtFindPart = Null
        End If
        Do Until i = 53
            Me.Controls("in" & i) = DLookup("[In-Week " & i & "]", [Parts], "(([Parts].[Part #]) = '" & txtFindPart & "')")
            Me.Controls("out" & i) = DLookup("[Out-Week " & i & "]", [Parts], "(([Parts].[Part #]) = '" & txtFindPart & "')")
            i = i + 1
        Loop
    End If
End Sub

Any help would be greatly appreciated.

asked Jun 19, 2015 at 11:38

spriore's user avatar

4

I figured it out the problem was that the table Parts Was not open and it was causing the error. I just had to add a line to open the table and at the end close it.

DoCmd.OpenTable "Parts"
Dim i As Integer
i = 1
If IsNull(txtFindPart) = False Then
    If Me.Recordset.NoMatch Then
        MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
        Me!txtFindPart = Null
    End If
    Do Until i = 53
        Me.Controls("in" & i) = DLookup("[In-Week " & i & "]", "[Parts]", "(([Parts].[Part #]) = '" & txtFindPart & "')")
        Me.Controls("out" & i) = DLookup("[Out-Week " & i & "]", "[Parts]", "(([Parts].[Part #]) = '" & txtFindPart & "')")
        i = i + 1
    Loop
End If
DoCmd.Close , "Parts"

answered Jun 19, 2015 at 13:25

spriore's user avatar

spriorespriore

6033 gold badges10 silver badges17 bronze badges

  • #1

Hello all
I am getting the following runtime error 2465 — Application-defined or Object-defined error when I run the following code.

Code:

Private Sub sfrm_Image_Count_Enter()
Dim rs As Recordset
Dim strSQL As String

strSQL = "SELECT * FROM tbl_Monthly_Estimate WHERE [ProjectID] = '" & Forms!frm_projectdata.ProjectKey & "' "
Set rs = CurrentDb.OpenRecordset(mySQL)

If rs!TableInformation = "tbl_TechTime" Then
Me.sfrm_Image_Count.LinkChildFields = "ProjectID"
Me.sfrm_Image_Count.LinkMasterFields = "ProjectKey"
Else
Me.sfrm_Image_Count.LinkChildFields = "ProjectID, Status"
Me.sfrm_Image_Count.LinkMasterFields = "ProjectKey, ServiceName"
End If

End Sub

What I want to do is change the link between the subform and form based on a field in the subform. If it is tbl_TechTime then I just want to link by the ProjectID to ProjectKey. If the field is tbl_History then I want to link by ProjectID to ProjectKey AND Status to ServiceName.

Thank you for any help you can give.

  • #2

2 things jump out at me first off.

1. Declare your recordset as DIM rs As DAO.Recordset

2. You need to change this line:
Set rs = CurrentDb.OpenRecordset(mySQL)

to this
Set rs = CurrentDb.OpenRecordset(strSQL)

Banana

split with a cherry atop.


  • #3

In addition to Bob’s excellent advice, you can get more information by doing this whenever you see a generic «Application or Object-defined Error»-

In the immediate windows of VBE, type:

Which will give you more detail about the error and help you with the debugging.

  • #4

In addition to Bob’s excellent advice, you can get more information by doing this whenever you see a generic «Application or Object-defined Error»-

In the immediate windows of VBE, type:

Which will give you more detail about the error and help you with the debugging.

Good stuff and one more thing I didn’t know that I will be adding to my «bag-o-tricks» :D

  • #5

Thank you both for the help, it now works.

bnw

Registered User.


  • #6

Hello, I need some help

I received the same above error in this code when I did a compilation. It stops at the second subformFees under the Else. It is indicating that it cannot recognize this field name. It is not a field. It is the name of the form. :(

Private Sub Toggle_View_Click()
If Me![Toggle View].Caption = » &View Fee Schedule» Then
Me![subformEvents].Visible = False
Me![subformFees].Caption = «&View Attendanees»

Else
Me![subformFees].Visible = False
Me![subformEvents].Visible = True
Me![Toggle View].Caption = «&View Fee Schedule»
End If
End Sub

Banana

split with a cherry atop.


gemma-the-husky


  • #8

sometimes vba seems to object to the use of currentdb

i find throwing in the extra

dim dbs as database
set dbs=currentdb

set rst=dbs.openrecordset etc

avoids these «scope type errors»

Понравилась статья? Поделить с друзьями:
  • Van 139 ошибка valorant
  • Vba счетчик ошибок
  • Vba ошибка 13 type mismatch как исправить
  • Vba проверить ячейку на ошибку
  • Vector 1350 ошибка 5027