Message box coding.

S

starkbergs

I am working on a form "A" and i have created a Message box that has
'yes' and 'No' options.

if i click on the yes button then it should open up a new form "B (in
this case FormAdd)"
But if i click on the No option then it should let me stay in the same
form that i have been working previsiouly.


I have this code here.Can anyone help me as to what i am missing
here.


Private Sub Form_Open(Cancel As Integer)
If IsNull(CompanyID) Or IsNull(InspectorID) Then
MsgBox "", vbYesNo + vbCritical + vbDefaultButton2
If Response = vbYes Then
DoCmd.OpenForm "", , , , acFormAdd
Else
If Response = vbNo then
Exit Sub
End if
 
A

Al Campagna

I don't see where you've Dim'd the Response variable, and the vbNo code is
not needed. If you click NO, the procedure just ends.

Try...
Private Sub Form_Open(Cancel As Integer)
Dim Response As Variant
If IsNull(Date1) Or IsNull(Date2) Then
Response = MsgBox("PromptText", vbYesNo + vbCritical +
vbDefaultButton2)
If Response = vbYes Then
DoCmd.OpenForm "FormB", , , , acFormAdd
End If
End If
End Sub
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
S

starkbergs

Thank you very much. It worked.

I don't see where you've Dim'd the Response variable, and the vbNo code is
not needed.  If you click NO, the procedure just ends.

Try...
Private Sub Form_Open(Cancel As Integer)
Dim Response As Variant
    If IsNull(Date1) Or IsNull(Date2) Then
        Response = MsgBox("PromptText", vbYesNo + vbCritical +
vbDefaultButton2)
            If Response = vbYes Then
                DoCmd.OpenForm "FormB", , , , acFormAdd
            End If
    End If
End Sub
--
    hth
    Al Campagna
    Microsoft Access MVP
   http://home.comcast.net/~cccsolutions/index.html

    "Find a job that you love... and you'll never work a day in your life."









- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top