Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > Define control within a Tab page from a module
 

Define control within a Tab page from a module

Hi There,

I amcurrently building a MDI application.

Both my Add and Edit screen use a form called frmStaffDetails.

On load, this form is redefined as 'AddStaffChild' and 'EditStaffChild' dependant on which menu item is selected.

I've defined the CurrentForm as Form.ActiveForm.ActiveMdiChild.

Within a module I am checking the text withincertain textboxes. So for example here I am checking a name has been inputted. If it has, then I will allow the record to be saved.

Public

Sub CheckStaffSave()

If

Not CurrentForm.Controls("txtFirstName").Text = "" Then

MsgBox(

"You are about to enter this record into the database do you wish to continue?", MsgBoxStyle.YesNoCancel)

If vbOK Then

SaveStaffRecord()

ClearStaffBoxes()

Else

Exit Sub

End If

The problem I am having is that this code works perfectly if the textbox control is not within a Tab Control. As soon as I put it in a tab page I get the error.

"Referenced object item has a value of Nothing"

Also if I reference it directly for example

If Not AddStaffChildForm.txtFirstName.Text = ""

this works fine too, but i want it to be more genric so I can use it for my edit screen as well.

How can I define a control within a Tab Control from a module (or any otherway to declare a public sub).

Cheers

TantrumLindsey  20 hours 11 minutes ago
Hi,

use it like:


If Not CurrentForm.Controls("YourTabControl").Controls("YourTabPage").Controls("YourTextBox").Text
 = "" Then

End If


and btw. for posting code please use the button.
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
Heslacher  18 hours 42 minutes ago

The codewent allmessy whenafter I posted. Here it is again:


Public Sub CheckStaffSave()

If Not CurrentForm.Controls("txtFirstName").Text = "" Then

MsgBox("You are about to enter this record into the database do you wish to continue?", MsgBoxStyle.YesNoCancel)

If vbOK Then

SaveStaffRecord()
ClearStaffBoxes()

Else

Exit Sub

End If

TantrumLindsey  18 hours 54 minutes ago
Hi,

use it like:


If Not CurrentForm.Controls("YourTabControl").Controls("YourTabPage").Controls("YourTextBox").Text
 = "" Then

End If


and btw. for posting code please use the button.
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
Heslacher  18 hours 42 minutes ago
Brilliant. Thank you very much.
TantrumLindsey  18 hours 25 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• disable case-sensitivity in code | start only if get some data
• Noobie Help with Strings - Visual Basic 2005
• about socket's accept method in vb 2003?
• Datagridview - Row change event?
• EndEdit vs. EndCurrentEdit
• get text after first space
• Problem With Automating Outlook
• Pull Software data from Registry
• How can I edit files (like hex editing)
• explicit conversion from object to array