Variable Names

deepheat101

Board Regular
Joined
Jul 26, 2006
Messages
138
Greetings (again)

On my MultiPage UserForm that has potentially 20 pages with each page containing three TextBox. I am attempting to perform the following data validation - if the page is visible then none of the three TextBoxes that exist on that page can be blank. If a TextBox is blank SetFocus to it.

The naming convention that I have used for the TextBoxes is as follows...

Code:
 Page1     Page2      Page3      Page4   etc.....
txtBox11  txtBox12   txtBox13   txtBox14
txtBox21  txtBox22   txtBox23   txtBox24
txtBox31  txtBox32   txtBox33   txtBox34


Code:
For PageNumber = 1 To 20
        
  If frmMain.MultiPage1.Pages(PageNumber).Visible = True Then
            
    Select Case ""
      Case .Pages(PageNumber).txtBox1 & PageNumber
        frmMain.txtBox1 & PageNumber.SetFocus               '<<<<<<<<<<
                
      Case .Pages(PageNumber).txtBox2 & PageNumber
        frmMain.txtBox2 & PageNumber.SetFocus               '<<<<<<<<<<

      Case .Pages(PageNumber).txtBox3 & PageNumber
        frmMain.txtBox3 & PageNumber.SetFocus               '<<<<<<<<<<

    End Select
            
  End If
        
Next

The code marked with "<<<<<<<<<<" does not get past the VBA syntax checker Interestingly, the Case statements pass the syntax checker but fail at run time. What is the correct code for these lines?

Many Thanks

dp
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Explain what you mean by this:

Code:
Select Case ""
 
Upvote 0
Explain what you mean by this:

Code:
Select Case ""

Code:
If "" = .Pages(PageNumber).txtBox1 & PageNumber Then
....
If "" = .Pages(PageNumber).txtBox2 & PageNumber Then
....
If "" = .Pages(PageNumber).txtBox3 & PageNumber Then
....
 
Upvote 0
Take a look at the controls collection.
Code:
Me.Controls("txtbox1" & PageNumber)
 
Upvote 0
so in every instance you'd be comparing a blank to something. Normally you do:

Select Case variable_name

not a constant. It defeats the purpose of the construct.
 
Upvote 0
It doesn't seem like Case is what you want here to me either. I'm with Norie - maybe you are trying to loop through a collection of textbox controls.

This is interesting:
Code:
If "" = .Pages(PageNumber).txtBox1 & PageNumber Then

You'll never get a true result if PageNumber isn't = "" which I doubt it is!

I'm not seeing the syntax error but the logic is puzzling. Are you sure you have the correct With-End structure -- i.e., to go with .Pages(PageNumber).txtBox1

--AB
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top