472,784 Members | 967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 software developers and data experts.

Checking for empty text boxes

I am using Visual Basic for a Psychology experiment and I would like to check and see if the participants answered all of the questions on one form before moving on to the next. So far this is what I have done and it is not working.

If txbAge.Text = String.Empty Then
MsgBox("Wie Alt bist du?")
Else : Me.Hide()
AnagramExample.ShowDialog()
End If
If female.Checked = False And male.Checked = False Then
MsgBox("Was ist dein Geschlecht?")
Else : Me.Hide()
AnagramExample.ShowDialog()
End If
If txbMajor.Text = String.Empty Then
MsgBox("Was studierst du")
Else : Me.Hide()
AnagramExample.ShowDialog()
End If
If txbSemester.Text Is Nothing Then
MsgBox("In welchem Semester bist du?")
Else : Me.Hide()
AnagramExample.ShowDialog()
End If

Using this code, it does check to see if the textboxes are empty but if the participant clicks on the next button without answering any of the questions the message boxes appear one after the other and then the next form appears without giving the participant the chance to answer the items they missed. I am sure this code is not the most efficient or best way to do this (obviously since it isn't working) and would appreciate any and all help. I am completely new at programming.

Thanks!
Nov 1 '11 #1
2 2372
Killer42
8,435 Expert 8TB
That's because you are not stopping after you check each one. I'd suggest adding Exit Sub after each MsgBox.

Also, I'd recommend removing the extra ":" after each Else.

By the way, judging from the syntax, I'd guess you'll get a better response in the Visual Basic .Net forum. This one is for much older versions of VB, which work a bit differently.
Dec 18 '11 #2
While is not working is because you are asking the program to move to the next form if any of the textboxes is not empty.
You are supposed to check for all textboxes before call .ShowDialog
Try the below codes I believed it should work and post your feedback.
Expand|Select|Wrap|Line Numbers
  1. If txbAge.Text = String.Empty Then
  2. MsgBox("Wie Alt bist du?")
  3.  
  4. ElseIf txbSemester.Text Is Nothing Then
  5. MsgBox("In welchem Semester bist du?")
  6.  
  7. ElseIf txbMajor.Text = String.Empty Then
  8. MsgBox("Was studierst du")
  9.  
  10. ElseIf female.Checked = False And male.Checked = False Then
  11. MsgBox("Was ist dein Geschlecht?")
  12. Else 
  13. Me.Hide()
  14. AnagramExample.ShowDialog()
  15. End If
  16.  
Jul 22 '20 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: KathyB | last post by:
Hi, I'm trying to find a way to validate input text boxes where I don't know the names until the page is rendered. I've got 2 validate functions that fire with the onsubmit button of a "mini" form...
3
by: Derek | last post by:
I am trying to add the text of several textboxes as a sum using the + sign but even converting to integer it is concatenating. Any help would be greatly appreciated. Dim price1 As...
7
by: Gertjan van Heijst | last post by:
Hi, I really hope someone can help me because I've already spend 2 days on this problem and I'm not getting anywhere. I think the problem is that I don't really understand how text boxes store...
7
by: RC | last post by:
I have a form with five text boxes on it. The format for all the boxes is set as General Number. In four of the boxes the user can enter a number, the fifth box totals up the values in the other...
4
by: Enterprise | last post by:
Hi, I have 25 text boxes in a form. Lets say TB1 through TB25 are the Names of the boxes. They have no controll sources. I want to be able to check whether the text box is empty. Is there anyway I...
7
by: Mark | last post by:
Hi All, I have a report which is based on a query which is used to produce QC check sheets. I have quite a few text boxes which are used to display questions depending on the value of one...
0
by: Marty U. | last post by:
I am building a 3 level deep heirarchy tree for an application requirement. I need the ability at any level to add an item to the tree. However, when something is added all 3 levels must be...
1
by: adarshyam | last post by:
can anybody tel me how to clear values from dynamically created text boxes?? using a clear button.. this is the code used to create dynamic text boxes.. if i press clear button then it must clear all...
11
by: jwessner | last post by:
I have a form (Form1) which contains basic Project data and a subform listing the personnel assigned to the Project as a continuous form. Selecting a person on that project and clicking on a command...
12
Dheeraj Joshi
by: Dheeraj Joshi | last post by:
Hi i have a problem. I have 7 text boxex with different id's. I want to run a script via AJAX and i want to populate the result of the script in to these text boxes. The code is function...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.