user select ID and get the form with data by that ID, but what if the ID not exists??

Ankie

Registered User.
Local time
Today, 20:11
Joined
Apr 18, 2006
Messages
15
Hello everyone,

I've made a form where the user can fill in a field ID... and than by clicking on a button another form will be opened with the data of that person (with that ID that's filled in). But if the user fill in an ID that is not currently in the database, there will be also shown another form, but than with no data.. Now I want that if the ID is not known, to display a message or something (like "this ID is not known, try again") and not to open the form..

I've used the following code under the button:

Private Sub openenFormulier_Click()
On Error GoTo Err_openenFormulier_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Onderzoek"

stLinkCriteria = "[Qr_Ant_PG.ID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_openenFormulier_Click:
Exit Sub

Err_openenFormulier_Click:
MsgBox Err.Description
Resume Exit_openenFormulier_Click

End Sub


Hopefully someone can help me!

Thanks,
Ankie
 
Last edited:
Use DCOUNT to check if there is a record already, if it returns zero, than there is no record and you can handle it as required.
MyVar = DCOUNT("ID","Qr_Ant_PG.ID","[Qr_Ant_PG.ID]='" & Me![ID] & "'"
IF MyVar = 0 then
No record exists
ELSE
Record exists
END IF
This assumes ID is a string (hence the single quotes), if it is nuermic, just remove the single quotes.
 
Thanks! Now it's solved :)
 

Users who are viewing this thread

Back
Top Bottom