Runtime error '2465' (1 Viewer)

boblife42

Registered User.
Local time
Today, 03:09
Joined
May 30, 2008
Messages
32
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.
 

boblarson

Smeghead
Local time
Today, 03:09
Joined
Jan 12, 2001
Messages
32,059
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.
Local time
Today, 03:09
Joined
Sep 1, 2005
Messages
6,318
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:

Code:
?AccessError(2465)

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

boblarson

Smeghead
Local time
Today, 03:09
Joined
Jan 12, 2001
Messages
32,059
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:

Code:
?AccessError(2465)

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
 

bnw

Registered User.
Local time
Today, 03:09
Joined
Sep 19, 2006
Messages
26
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
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:09
Joined
Sep 12, 2006
Messages
15,613
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"
 

Users who are viewing this thread

Top Bottom