ChrisLeicester
New member
- Local time
- Today, 08:27
- Joined
- Feb 14, 2025
- Messages
- 12
Hi All
I am writing vba to check if a record exists before I open a form and am going back to basics, doing one step at a time before adding the next step.
I have a query called [SearchPOQ] which lists all the purchase order numbers already entered.
I have a primary key field called [ProdOrderID]
For initial testing, my code just puts a message box to say record found or record not found.
When i run the code it gives the same 'Purchase Number Found' message whether I put a number in that I know I have or know I do not have.
Am I not understanding the else command. I was assuming that if the count was 0 it would say not found and if the count was 1 it would say found.
Should I use count and not Dcount, is Dcount counting a null record as 1?
Thanks
I am writing vba to check if a record exists before I open a form and am going back to basics, doing one step at a time before adding the next step.
I have a query called [SearchPOQ] which lists all the purchase order numbers already entered.
I have a primary key field called [ProdOrderID]
For initial testing, my code just puts a message box to say record found or record not found.
Code:
Private Sub SearchBTN_Click()
'check if any records exist
If DCount("[ProdOrderID]", "SearchPOQ") = 0 Then
MsgBox "Purchase Number Not Found", vbOKOnly, "Incorrect P.O. Number"
Else
MsgBox "Purchase Number Found", vbOKOnly, "Correct P.O. Number"
End If
End Sub
When i run the code it gives the same 'Purchase Number Found' message whether I put a number in that I know I have or know I do not have.
Am I not understanding the else command. I was assuming that if the count was 0 it would say not found and if the count was 1 it would say found.
Should I use count and not Dcount, is Dcount counting a null record as 1?
Thanks