conditional macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to create a condtional macro that prompts a message and gives the
option of opening a form if the text entered in a particular text box does
not auto populate other text boxes (relational database) e.g. By entering in
a non-existing customer id, no customer details appear. In this case i want a
message prompt informing the user that the customer ID entered does not exist
and allow the user to create a new customer record by opening the customer
form from the message prompt.
 
Allan
Let's call the text control where you'll enter the CustID to look for...
FindCustID
Using the AfterUpdate event of FindCustID...

Dim Response as string, Prompt as String, Title as String

If IsNull("[CustID]", "tblCustomers", "CustID =
Forms!YourFormName!FindCustID" Then
' The CustID does not exist... offer user 2 choices...
Prompt = "This Customer ID does not exist. OK = Add new Cancel =
Retry another CustID"
Title = "CustID Not Found"
Response=MsgBox(Prompt, vbOKCancel, Title)
If Response = vbOK then
' Open a form if needed or just go to a New record
DoCmd.GoToRecord , , acNewRec
ElseIf Response = vbCancel Then
FindCustID = ""
Exit Sub
End If
Else
' The CustID exists... Do your normal CustID Find code here
End if

Please check my typing for any syntax errors, but this is the concept...
Adjust to suit...
hth
Al Camp
 
Allana,

Construct your macro like this...

Condition: DCount("*","YourTable","[Customer ID]=" & [Customer ID])=0
Action: MsgBox
"No such customer"
Condition: ...
Action: OpenForm
Customer form
Condition: ...
Action: GoToRecord
New
 
Back
Top