Hello all,
I have this little bit of VBA that essentially:
A) checks to see if the user has actually entered a value into the input box
B) then uses DCOUNT to check the query used, that there are any records that match and if so :
C) Apply a filter to the subform datasheet to show only the records set by A.
Now A and C work when either no criteria is entered or the correct criteria is entered, but the check to see if there are any records that exist, using dcount does not work.
It's probably something wrong with my syntax or i'm using it the wrong way.
Can someone take a quick look ?
Many thanks
Damob
I have this little bit of VBA that essentially:
A) checks to see if the user has actually entered a value into the input box
B) then uses DCOUNT to check the query used, that there are any records that match and if so :
C) Apply a filter to the subform datasheet to show only the records set by A.
Now A and C work when either no criteria is entered or the correct criteria is entered, but the check to see if there are any records that exist, using dcount does not work.
It's probably something wrong with my syntax or i'm using it the wrong way.
Can someone take a quick look ?
Many thanks
Damob
Code:
Private Sub Search_Click()
Dim strQuery As String
Dim PCNumber As String
strQuery = "RepairHistoryQuery"
If IsNull(Me![PCNumberIn]) Then
MsgBox "You Must enter a PC number, or click cancel to exit", vbExclamation, "Search For PC"
Me.PCNumberIn.SetFocus
Else
PCNumber = Me!PCNumberIn
If DCount("PCNumber", "RepairHistoryQuery") > 0 Then
MsgBox "PC not Found.", vbInformation, "Search For PC"
Else
With Forms!RepairHistoryForm!RepairHistorySubForm.Form
.Filter = "PCNumber='" & Me!PCNumberIn & "'"
.FilterOn = True
End With
End If
DoCmd.Close acForm, "RepairHistorySearchForm"
End If
End Sub