how to make msgbox ?

J

Jon

I have a form has a text box to display data and there is a button to open
other form. What I want to do is when the use click the button without data
in the text box, a msgbox appears and tell the user that he/she must input a
data in the text box to display the data. And the other form does not open
until the text box filled.
How can I do that by using VB?
 
B

boblarson

Jon -

You just need to have this in the On Click event of the command button:

If Len(Me.YourTextBoxNameHere)=0 Then
MsgBox "You need to enter data in the text box" & vbCrLf & _
"to continue. Please try again.", vbExclamation, "Missing Data"
Exit Sub
Else
DoCmd.OpenForm "YourFormNameHere", acNormal
End If

--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
__________________________________
If my post was helpful to you, please rate the post.
 
J

Jon

thank you boblarson, but even if i put the date in the text box the msgbox
appears.
and one blank msgbox also appears , finally the other form also start.
any solving, this is my code:

Private Sub Command43_Click()
On Error GoTo Err_Command43_Click

Dim stDocName As String
Dim stLinkCriteria As String

If Len(Me.Text10) Or (Me.Text12) = 0 Then
MsgBox "You need to enter date " & vbCrLf & _
"to continue. Please try again.", vbExclamation, "Missing Data"
Exit Sub
Else
stDocName = "Specifed by date"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Err_Command43_Click:
MsgBox Err.Description
Resume Exit_Command43_Click

Exit_Command43_Click:
Exit Sub
End Sub
 
R

rico

You need to split your if statment out like so:

If Len(Me.Text10) = 0 OR Len(Me.Text12)=0 THEN

etc...

Personally i would give them seperate statements so that the user knows
which one they need to enter:

You can also set the focus to a control so its even clearer what they need
to do This would be my way of doing it:

If Len(Me.Text10) = 0 then
Msgbox "Enter Date"
Me.text10.setfocus
Exit Sub
End If

If Len(Me.Text12) = 0 then
Msgbox "Enter Other"
Me.text12.setfocus
Exit Sub
End If

stDocName = "Specifed by date"
DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

HTH Rico
 

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