Help with Message box code

T

Tony Williams

I have a form that the user has to input two dates and then clicks a command
button to run a query. If either or both of the dates are empty I want a
message box to pop up. If they are completed then I want a message box to
open to say that the query is about to update the records (I want to use my
own message not the Access standard message). However although the msgbox
appears if the date is blank the code still tries to run the query. I want
the code to send the user back to the form. Here is my code:
Private Sub cmdupdateIrish_Click()
On Error GoTo Err_cmdupdateIrish_Click

Dim stDocName As String
Dim Msgstr As String
Dim Msgstr2 As String
stDocName = "qryYTDUpdateIrish"
Msgstr = "You are about to update the files for the Euro zone companies
" _
& "by calculating the quarterly data from the YTD data" & vbCrLf &
vbCrLf _
& "Are you sure you want to do that?"
Msgstr2 = "To update the data you must enter the current quarter!"
Msgstr3 = "To update the data you must enter the previous quarter!"
If IsNull(Forms!frmdate4Irish!txtqtr2) Or Forms!frmdate4Irish!txtqtr2 =
"" Then
If MsgBox(Msgstr2, vbExclamation, "Current quarter missing") = vbOK Then
Cancel = True
Else
If IsNull(Forms!frmdate4Irish!txtqtr3) Or Forms!frmdate4Irish!txtqtr3 =
"" Then
If MsgBox(Msgstr2, vbExclamation, "Previous quarter missing") = vbOK
Then
Cancel = True
End If
End If
End If
End If
If MsgBox(Msgstr, vbYesNo, "Updating Euro data") = vbNo Then
DoCmd.Close acForm, Me.Name
Cancel = True
Else
DoCmd.OpenQuery stDocName, acNormal, acEdit

End If
Exit_cmdupdateIrish_Click:
Exit Sub

Err_cmdupdateIrish_Click:
MsgBox Err.Description
Resume Exit_cmdupdateIrish_Click
End Sub


Where am I going wrong?
Thanks
Tony
 
S

Svetlana

Me.txtqtr2.SetFocus
If Nz(Me.txtqtr2.Text)<>"" Then
Me.txtqtr3.SetFocus
If Nz(Me.txtqtr3.Text)<>"" Then
If MsgBox(Msgstr)=vbNo Then
DoCmd.Close
Else
'you open your query
End If
Else
MsgBox (Msgstr3)
Me.txtqtr3.SetFocus
End If
Else
MsgBox (Msgstr2)
Me.txtqtr2.SetFocus
End If

Cancel=True doesn't work here.
 

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