Cannot resolve error 2109 (1 Viewer)

David44Coder

Member
Local time
Tomorrow, 09:31
Joined
May 20, 2022
Messages
109
A dbl-click event in Form2 should call a Sub in Form1 the close. But Access will not exceute it.
It tells me
Run—time error '2109':
There is no field named 'cboCode' in the current record.

And there's not... but why would Access be looking for it ? Should it not just follow the code instructions ?
But if click Debug I can step through perfectly and the subroutine in Form1 executes correctly'

Form2 code
Code:
Private Sub Code_DblClick(Cancel As Integer)
    Form_Form1.GotoCode (Code)  '>>>>>>>>>>> this is the line halted in yellow
    DoCmd.Close acForm, "Form2"
End Sub

Form1 code
Code:
Sub GotoCode(x)
    DoCmd.GoToControl "cboCode"
    Me!txtCode2 = x
    DoCmd.FindRecord Me![txtCode2]
End Sub
Thanks for any help with this.
 

David44Coder

Member
Local time
Tomorrow, 09:31
Joined
May 20, 2022
Messages
109
Haha I think it may have been too dumb a question to get any answers!
Form1 was still open at the start of Sub GotoCode. So I'm passing the value via Property Let then closing Form2
 

KitaYama

Well-known member
Local time
Tomorrow, 06:31
Joined
Jan 6, 2022
Messages
1,540
I have not used GotoCode ever.
When I want to run a code in another form I use :

Code:
    If IsLoaded(MySecondForm) Then
        Forms(MySecondForm).SetFocus
        Forms(MySecondForm).MyFucnctionName
    End If

Of course both forms should be open. (or opened and not visible)
 

moke123

AWF VIP
Local time
Today, 17:31
Joined
Jan 11, 2013
Messages
3,913
Why not just run the code all within form2?

Code:
Dim frm As Form
    Set frm = Forms("Form1")
    With frm

        Dim rs As DAO.Recordset
        Set rs = frm.RecordsetClone

        rs.FindFirst "YourPKValue = " &  me.SomeField    'adjust this to your needs
        If Not rs.NoMatch Then
            frm.Bookmark = rs.Bookmark
        End If

    End With

   set frm = nothing
 

Users who are viewing this thread

Top Bottom