This is what I'm trying to do. I created a form for a user to enter a name. The information is saved in SQL DB employees table. The employees table auto number is assign to global variable GBL_ID as shown is first code. By clicking the proceed button on the first form I can follow the GBL_ID variable to the second form in debug mode.
While hitting F8 I can follow the process until a I get an error message:
Object variable or with block variable not set.
What am I doing wrong? It's got to be so simple. Any help will be appreciated. Thanks.
-------------------------------------------------------------------------------------------------------
Private Sub Btn_Proceed_Click()
On Error GoTo Err_Btn_Proceed_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim strFields As String
Dim strQueryName As String
If IsEmpty(Trim(Me!Text31)) Or IsNull(Trim(Me!Text31)) Or Trim(Me!Text31) = "" Then
MsgBox "Please enter your First Name"
Exit Sub
End If
If IsEmpty(Trim(Me!Text33)) Or IsNull(Trim(Me!Text33)) Or Trim(Me!Text33) = "" Then
MsgBox "Please enter your Last Name"
Exit Sub
End If
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
'set ID to global value
GBL_ID = CInt(Me.Text48)
'Insert a new record and create a new query for CPA Table
DoCmd.RunSQL "Insert into CPA (ID) values (" & GBL_ID & ");"
strSQL = "Select * from CPA where ID = " & GBL_ID & " ;"
DoCmd.Close acForm, Me.Name
stDocName = "CPA_form_1"
stLinkCriteria = "ID = " & GBL_ID
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Btn_Proceed_Click:
Exit Sub
Err_Btn_Proceed_Click:
MsgBox Err.Description
Resume Exit_Btn_Proceed_Click
End Sub
--------------------------------------------------------------------------------------------
Private Sub Continue1_button_Click()
On Error GoTo Err_Continue1_button_Click
Dim stDocName As String
Dim stLinkCriteria As String
'Validates Option Buttons have been chosen
If Me.Frame1.Value = 0 Then
MsgBox "Please recheck answer(s) to ensure option button was selected."
'Me.Frame1.BackColor = RGB(255, 0, 0)
Exit Sub
End If
'Insert a new record and create a new query for CPA Table
CurrentDb.Execute "Insert into CPA (Q1) values (" & Me.Frame1 & ");"
strSQL = "Select Q1 from CPA where ID = " & GBL_ID & " ;"
stDocName = "CPA_form_2"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Continue1_button_Click:
Exit Sub
Err_Continue1_button_Click:
MsgBox Err.Description
Resume Exit_Continue1_button_Click
End Sub