limhockmeng
New Member
- Joined
- May 3, 2012
- Messages
- 2
Hi folks,
I have the following coding that display a message should one of the mandatory fields be empty (validation). Now, my problem is that the placing of the variables in the MsgBox is hardocded, i.e. if all fields are filled except Postal code, Postal code will appear in the last line instead of first line of the msgbox. How can i make the code more versatile as in it will auto shift the position of the variable up.
Please advise.
Many thanks
Current placing order:
LastName
FirstName
EmployeeNumber
Address 1
Country
Postal Code
'Coding
---------------
Private Sub Page2Next_Click()
Dim Page2MsgLastName As String
Dim Page2MsgFirstName As String
Dim Page2MsgEmployeeNumber As String
Dim Page2MsgAddressLineBox1 As String
Dim Page2MsgCountryBox As String
Dim Page2MsgPostalCodeBox As String
If LastNameBox.Text = "" Then
Page2MsgLastName = "Last Name"
End If
If FirstNameBox.Text = "" Then
Page2MsgFirstName = "First Name"
End If
If EmployeeNumberBox.Text = "" Then
Page2MsgEmployeeNumber = "Employee Number"
End If
If AddressButtonYes = True Then
If AddressLineBox1.Text = "" Then
Page2MsgAddressLineBox1 = "Address Line 1"
End If
If CountryBox.Text = "" Then
Page2MsgCountryBox = "Country"
End If
If PostalCodeBox.Text = "" Then
Page2MsgPostalCodeBox = "Postal Code"
End If
End If
If AddressButtonNo = True Then
If LastNameBox.Text = "" Or FirstNameBox.Text = "" Or EmployeeNumberBox.Text = "" Then
MsgBox "Please enter the following fields:" & vbCr & vbCr & Page2MsgLastName & vbCr & Page2MsgFirstName & vbCr & Page2MsgEmployeeNumber, vbCritical, "Blank Fields Detected"
Else
'Advance by one page
iPageNo = MultiPage1.Value + 1
MultiPage1.Pages(iPageNo).Visible = True
MultiPage1.Value = iPageNo
End If
End If
If AddressButtonYes = True Then
If LastNameBox.Text = "" Or FirstNameBox.Text = "" Or EmployeeNumberBox.Text = "" Or AddressLineBox1.Text = "" Or CountryBox.Text = "" Or PostalCodeBox.Text = "" Then
MsgBox "Please enter the following fields:" & vbCr & vbCr & Page2MsgLastName & vbCr & Page2MsgFirstName & vbCr & Page2MsgEmployeeNumber & vbCr & Page2MsgAddressLineBox1 & vbCr & Page2MsgCountryBox & vbCr & Page2MsgPostalCodeBox, vbCritical, "Blank Field Detected"
Else
'Advance by one page
iPageNo = MultiPage1.Value + 1
MultiPage1.Pages(iPageNo).Visible = True
MultiPage1.Value = iPageNo
End If
End If
End Sub
I have the following coding that display a message should one of the mandatory fields be empty (validation). Now, my problem is that the placing of the variables in the MsgBox is hardocded, i.e. if all fields are filled except Postal code, Postal code will appear in the last line instead of first line of the msgbox. How can i make the code more versatile as in it will auto shift the position of the variable up.
Please advise.
Many thanks
Current placing order:
LastName
FirstName
EmployeeNumber
Address 1
Country
Postal Code
'Coding
---------------
Private Sub Page2Next_Click()
Dim Page2MsgLastName As String
Dim Page2MsgFirstName As String
Dim Page2MsgEmployeeNumber As String
Dim Page2MsgAddressLineBox1 As String
Dim Page2MsgCountryBox As String
Dim Page2MsgPostalCodeBox As String
If LastNameBox.Text = "" Then
Page2MsgLastName = "Last Name"
End If
If FirstNameBox.Text = "" Then
Page2MsgFirstName = "First Name"
End If
If EmployeeNumberBox.Text = "" Then
Page2MsgEmployeeNumber = "Employee Number"
End If
If AddressButtonYes = True Then
If AddressLineBox1.Text = "" Then
Page2MsgAddressLineBox1 = "Address Line 1"
End If
If CountryBox.Text = "" Then
Page2MsgCountryBox = "Country"
End If
If PostalCodeBox.Text = "" Then
Page2MsgPostalCodeBox = "Postal Code"
End If
End If
If AddressButtonNo = True Then
If LastNameBox.Text = "" Or FirstNameBox.Text = "" Or EmployeeNumberBox.Text = "" Then
MsgBox "Please enter the following fields:" & vbCr & vbCr & Page2MsgLastName & vbCr & Page2MsgFirstName & vbCr & Page2MsgEmployeeNumber, vbCritical, "Blank Fields Detected"
Else
'Advance by one page
iPageNo = MultiPage1.Value + 1
MultiPage1.Pages(iPageNo).Visible = True
MultiPage1.Value = iPageNo
End If
End If
If AddressButtonYes = True Then
If LastNameBox.Text = "" Or FirstNameBox.Text = "" Or EmployeeNumberBox.Text = "" Or AddressLineBox1.Text = "" Or CountryBox.Text = "" Or PostalCodeBox.Text = "" Then
MsgBox "Please enter the following fields:" & vbCr & vbCr & Page2MsgLastName & vbCr & Page2MsgFirstName & vbCr & Page2MsgEmployeeNumber & vbCr & Page2MsgAddressLineBox1 & vbCr & Page2MsgCountryBox & vbCr & Page2MsgPostalCodeBox, vbCritical, "Blank Field Detected"
Else
'Advance by one page
iPageNo = MultiPage1.Value + 1
MultiPage1.Pages(iPageNo).Visible = True
MultiPage1.Value = iPageNo
End If
End If
End Sub