Thank you for your responses. I have fixed the code, but know I can do better in defining with dim. Example 1 is the code written and works. Example 2 is more of what I would like to advance my code for improved coding. I am fairly new to vba and have learned on my own. Insight as to why it returns Invalid qualifier would be helpful.
Example 1: Works
Code:
Option Compare
DatabaseOption Explicit
Private Sub cmdClose_Click()
'Define
Dim Month0 As String
Dim Month1 As String
Dim Month2 As String
Dim MissingEntries As String
Dim msg As String
Dim button As Variant
Dim Title As String
Dim Response As Variant
msg = "Your are attempting to file this entry without a count. If you continue, this entry will be deleted."
button = vbYesNo + vbDefaultButton2
Title = "Missing Required Information"
Response = MsgBox(msg, button, Title)
'Fields are required and cannot save if IsNull
If Not (IsNull([txtCount])) And Not (IsNull([dtDateActivity])) Then
DoCmd.GoToRecord , , acNewRec
Forms!frmNavMain!frmNavMain.Form.lstMonth0.Requery
Forms!frmNavMain!frmNavMain.Form.lstMonth1.Requery
Forms!frmNavMain!frmNavMain.Form.lstMonth2.Requery
Forms!frmNavMain!frmNavMain.Form.lstMissingEntries.Requery
DoCmd.Close
Else
'If IsNull, then msgbox with yes/no
If (IsNull([txtCount])) Or (IsNull([dtDateActivity])) Then
'If no, then return to form with set focus
If Response = vbNo Then
[dtDateInvoice].SetFocus
'if yes, then undo, close form and requery loaded form
Else
Me.Undo
Forms!frmNavMain!frmNavMain.Form.lstMonth0.Requery
Forms!frmNavMain!frmNavMain.Form.lstMonth1.Requery
Forms!frmNavMain!frmNavMain.Form.lstMonth2.Requery
Forms!frmNavMain!frmNavMain.Form.lstMissingEntries.Requery
DoCmd.Close
End If
End If
End If
End Sub
Example 2 returns Invalid qualifier.
Code:
Option Compare
DatabaseOption Explicit
Private Sub cmdClose_Click()
'Define
Dim Month0 As String
Dim Month1 As String
Dim Month2 As String
Dim MissingEntries As String
Dim msg As String
Dim button As Variant
Dim Title As String
Dim Response As Variant
msg = "Your are attempting to file this entry without a count. If you continue, this entry will be deleted."
button = vbYesNo + vbDefaultButton2
Title = "Missing Required Information"
Response = MsgBox(msg, button, Title)
'when using below, returns Invalid qualifier
Month0 = Forms!frmNavMain!frmNavMain.Form.lstMonth0
Month1 = Forms!frmNavMain!frmNavMain.Form.lstMonth1
Month2 = Forms!frmNavMain!frmNavMain.Form.lstMonth2
MissingEntries = Forms!frmNavMain!frmNavMain.Form.lstMissingEntries
'Fields are required and cannot save if IsNull
If Not (IsNull([txtCount])) And Not (IsNull([dtDateActivity])) Then
DoCmd.GoToRecord , , acNewRec
Month0.Requery
Month1.Requery
Month2.Requery
MissingEntries.Requery
DoCmd.Close
Else
'If IsNull, then msgbox with yes/no
If (IsNull([txtCount])) Or (IsNull([dtDateActivity])) Then
'If no, then return to form with set focus
If Response = vbNo Then
[dtDateInvoice].SetFocus
'if yes, then undo, close form and requery loaded form
Else
Me.Undo
Month0.Requery
Month1.Requery
Month2.Requery
MissingEntries.Requery
DoCmd.Close
End If
End If
End If
End Sub