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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with msgbox code!

Status
Not open for further replies.

MsPeppa

Programmer
Jun 27, 2001
19
US
Jeff Bridgham showed me the following code in a thread where I asked

"I have a form and it has about four fields. Filenumber, last name, first name. What I want to do is if one or more of these fields are blank when the user tries to add a new record or to save the current one, I want a msgbox to appear stating which fields need to be completed."

A msgbox does appear with "needs to be filled in" but it is not displaying what fields need to be filled in, it is somehow not adding the needed fields to the list. Can someone tell me what is wrong with the code below that is not enabling it to work. I'm a newbie and I have no idea what to look for. Thanks

Dim Msg As String
Dim cntl As Control

Msg = ""
For Each cntl In Me.Controls
If cntl.ControlType = acTextBox Then
If IsNull(cntl.Value) = True Then
Msg = Msg & cntl.Value & " "
End If
End If
Next cntl

If Msg = "" Then
Msg = "All fields are correct"
Else
Msg = Msg & "need to be filled in."
End If

Call MsgBox(Msg)

 
Change Msg = Msg & cntl.Value & " " to Msg = Msg & cntl.Name & " "

Maq B-)
<insert witty signature here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top