Hello guys, thanks again for taking the time to help me out with my problems!
This problem seems super simple in my head, however getting the coding to make it work is turing out to be not so simple...
Basically what I am trying to do is have a Command Button check to see whether the current "Record ID" exists in the sister table before opening the sister table's bound form for editing when the user clicks on it.
I figured that I would be able to do this with a SELECT query that does a search for the current record's "Record ID" in the sister table, and couple it with an "If Then" statement that will either a) allow access to the form or b) pop up a MsgBox if the results of the SELECT query are Null or Empty and disallow access.
From my research the code below should work, but Access keeps getting hung up on the "Dim db As Database" line, and I cannot for the life of me figure it out!
This problem seems super simple in my head, however getting the coding to make it work is turing out to be not so simple...
Basically what I am trying to do is have a Command Button check to see whether the current "Record ID" exists in the sister table before opening the sister table's bound form for editing when the user clicks on it.
I figured that I would be able to do this with a SELECT query that does a search for the current record's "Record ID" in the sister table, and couple it with an "If Then" statement that will either a) allow access to the form or b) pop up a MsgBox if the results of the SELECT query are Null or Empty and disallow access.
From my research the code below should work, but Access keeps getting hung up on the "Dim db As Database" line, and I cannot for the life of me figure it out!
Code:
Private Sub GoToCertifiedBUTTON_Click()
On Error GoTo Err_GoToCertifiedBUTTON_Click
Dim VerifyExists As String
VerifyExists = "SELECT tbl_VEH4b.AppID " & _
"FROM tbl_VEH4a LEFT JOIN tbl_VEH4b ON tbl_VEH4a.ID = tbl_VEH4b.AppID " & _
"WHERE (([Forms]![frm_VEH4a].[ID]=[AppID]));"
Dim db As Database
Dim rs As Recordset
Dim qdf As QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("VerifyExists")
Set rs = qdf.openrecordset()
If rs.EOF Then
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frm_VEH4b"
stLinkCriteria = "[AppID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
'Open MsgBox with "Cannot Allow" Message
End If
Exit_GoToCertifiedBUTTON_Click:
Exit Sub
Err_GoToCertifiedBUTTON_Click:
MsgBox Err.Description
Resume Exit_GoToCertifiedBUTTON_Click
End Sub
Comment