Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Y/N Message Box - Yes Click does not Open Form 1

Status
Not open for further replies.

RobertIngles

Technical User
Jan 20, 2011
113
CA
Can anyone tell me what is wrong with my code? Clicking "Yes" when the msg box pops up doesn't open the specified form. What have I done wrong?

Private Sub Command4_Click()
'Create var.
Dim intChk As Integer

'This line counts the number of rec instances in TBLLaptop.
intChk = DCount("*", "tblLaptop", "Barcode = '" & Forms!QRYJustBarcodes!Barcode & "'")

'Does the rec exist? If not then open FRMCreateNewLaptopandUserV3 to add the new user details.

If intChk = 0 Then 'No?

MsgBox "This Laptop Does Not Exist, Do You Wish to Create Laptop Profile", vbYesNo + vbQuestion, "Create New Laptop Profile?"
If Response = vbYes Then

DoCmd.OpenForm "FRMCreateNewLaptopandUserV3", acNormal, , , acFormAdd


End If
End If
End Sub


 
As written the below does not return any value
Code:
   MsgBox "This Laptop Does Not Exist, Do You Wish to Create Laptop Profile", vbYesNo + vbQuestion, "Create New Laptop Profile?"
    If Response = vbYes Then

would have to be
Code:
dim response as long

response = MsgBox ("This Laptop Does Not Exist, Do You Wish to Create Laptop Profile", vbYesNo + vbQuestion, "Create New Laptop Profile?")

Always use "Option Explicit" and you would have found this problem because the code would not compile.
 
Thanks for your help MajP - works now except that the form opens up in edit/view all records mode instead of add. I'm sure the DoCmd.OpenForm statement is correct as I have used it in other forms. Suggestions?

Thanks
Robert
 
Figured it out - re-wrote the openform statement and it works now.

Thanks again MajP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top