JackieEVSC
Registered User.
- Local time
- Today, 09:20
- Joined
- Feb 24, 2012
- Messages
- 26
I am not fluent in VBA, so coding is very difficult for me! I could not figure out how to use the DCount, so I tried using DLookup to pass the value in a query field, but it's not working.
---In this example, "frm_RepairInfo-Asset" is a from based on the query "RepairInfo-SearchByAsset".
---I added a second query "RepairInfo-SearchByAsset2" that counts the records retrieved by the first query (the field is called "TestData").
---If "TestData" is zero, I want the form to go back to the Repair Menu on the Search tab and display a box that says "No matching records found."
---If "RepairInfo-SearchByAsset" HAS results, the value in the "TestData" in will be one or more, and I want the "frm_RepairInfo-Asset" form to open.
Here is my code:
Private Sub Command40_Click()
DoCmd.Close acForm, "frm_RepairMenu"
On Error GoTo fErr
DoCmd.OpenQuery "RepairInfo-SearchByAsset2", acViewNormal, acEdit
Dim SearchVal As String
SearchVal = DLookup("TestData", "RepairInfo-SearchByAsset2")
If SearchVal = "0" Then
DoCmd.Close acQuery, "RepairInfo-SearchByAsset2"
DoCmd.OpenForm "frm_RepairMenu", View:=acNormal, OpenArgs:="SearchRep"
MsgBox "Your search criteria found no matching records."
Else
DoCmd.OpenForm "frm_RepairInfo-Asset"
End If
Exit Sub
fErr:
DoCmd.OpenForm "frm_RepairMenu", View:=acNormal, OpenArgs:="SearchRep"
End Sub
This code is not working. I keep playing around with it, but I can't figure it out. (I know this is a comical effort on my part, but with limited VBA knowledge, this is all I can come up with.)
Can anyone point out my mistakes? Any help would be greatly appreciated.
Jackie
---In this example, "frm_RepairInfo-Asset" is a from based on the query "RepairInfo-SearchByAsset".
---I added a second query "RepairInfo-SearchByAsset2" that counts the records retrieved by the first query (the field is called "TestData").
---If "TestData" is zero, I want the form to go back to the Repair Menu on the Search tab and display a box that says "No matching records found."
---If "RepairInfo-SearchByAsset" HAS results, the value in the "TestData" in will be one or more, and I want the "frm_RepairInfo-Asset" form to open.
Here is my code:
Private Sub Command40_Click()
DoCmd.Close acForm, "frm_RepairMenu"
On Error GoTo fErr
DoCmd.OpenQuery "RepairInfo-SearchByAsset2", acViewNormal, acEdit
Dim SearchVal As String
SearchVal = DLookup("TestData", "RepairInfo-SearchByAsset2")
If SearchVal = "0" Then
DoCmd.Close acQuery, "RepairInfo-SearchByAsset2"
DoCmd.OpenForm "frm_RepairMenu", View:=acNormal, OpenArgs:="SearchRep"
MsgBox "Your search criteria found no matching records."
Else
DoCmd.OpenForm "frm_RepairInfo-Asset"
End If
Exit Sub
fErr:
DoCmd.OpenForm "frm_RepairMenu", View:=acNormal, OpenArgs:="SearchRep"
End Sub
This code is not working. I keep playing around with it, but I can't figure it out. (I know this is a comical effort on my part, but with limited VBA knowledge, this is all I can come up with.)
Can anyone point out my mistakes? Any help would be greatly appreciated.
Jackie