Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VB 6 Newbie
Message
 
To
02/04/2005 21:57:03
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
01001065
Message ID:
01001090
Views:
14
I would check for validation only in your submit button.
Private Sub cmdSubmit_Click()
  Dim strFieldNames As String

   If Me.txtFirstName.Text = "" Then
      strFieldNames = "First Name"
   End If

   If Me.txtLastName.Text = "" Then
      strFieldNames = strFieldNames & vbcrlf & "Last Name"
   End If

'if field is empty, alert user which field is empty
   If strFieldNames <> "" Then
      MsgBox "Missing Information: " & strFieldNames
   else
       'do you submit stuff here
   End If
End Sub
BTW, in your previous code, the declaration is at the wrong place. It should be in the General Declarations section (and not in the form load). Add "Option Explicit" at the top of your code and you will get an error related to that variable.


>I have created a form with various TextBoxes and a Submit button. What I need to accomplish is when the user clicks "Submit", it will display a messagebox informing the user which field isn't completed. My setup so far...
>
>
>====================================================
>Private Sub Form_Load()
>
>'create variable to store field name
>  Dim strFieldName As String
>
>End Sub
>====================================================
>Private Sub txtFirstName_Change()
>
>'store the textbox name, used for cmdSubmit
>   If Me.txtFirstName.Text = "" Then
>      strFieldName = "First Name"
>   Else
>      strFieldName = ""
>   End If
>End Sub
>====================================================
>Private Sub cmdSubmit_Click()
>
>'if field is empty, alert user which field is empty
>   If Not strFieldName = "" Then
>      MsgBox "Missing Information: " & strFieldName
>   End If
>
>End Sub
>====================================================
>
>
>This will display a messagebox everytime the Submit button is clicked, whether the field is empty or not. And it does not display strFieldName. Maybe I looked over something small. I've been trying to figure this out for a while. Any feedback welcome! Thanks!
>
>-wh0racle
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform