I reformatted your code for readability.
Please show all of your code related to this snippet. You must have this in some event that says
Private Sub....... and ends with End Sub
Try using this code which includes some debug statements to print messages in the immediate window.
Also, why are you opening a table?
Code:
Const MESSAGETEXT = "No Customer Number entered."
Dim strCriteria As String
strCriteria = "[SoldTo]" = """ & Me.SoldTo & """""
Debug.Print "strCriteria is <" & strCriteria & ">"
Debug.Print "Me.SoldTo is <" & Me.soldTo & ">"
Debug.Print " DCount1 is: " & DCount("SoldTo", "qry_List_RGM_Exclusion", strCriteria)
Debug.Print " DCount2 is: " & DCount("*", "qry_List_NoRGM_Exclusion", strCriteria)
Debug.Print " DCount3 is: " & DCount("SoldTo", "qry_NoList_RGM_Exclusion", strCriteria)
If Not IsNull(Me.SoldTo) Then
DoCmd.OpenQuery "qry_List_RGM_Exclusion", acViewNormal, acReadOnly
If DCount("SoldTo", "qry_List_RGM_Exclusion", strCriteria) = 0 Then
DoCmd.OpenQuery "qry_List_NoRGM_Exclusion", acViewNormal, acReadOnly
ElseIf DCount("*", "qry_List_NoRGM_Exclusion", strCriteria) = 0 Then
DoCmd.OpenQuery "qry_NoList_RGM_Exclusion", acViewNormal, acReadOnly
ElseIf DCount("SoldTo", "qry_NoList_RGM_Exclusion", strCriteria) = 0 Then
DoCmd.OpenTable "tbl_mat", acViewNormal, acReadOnly
End If
Else
MsgBox MESSAGETEXT, vbExclamation, "Invalid Operation"
End If