Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Load a form and call a function right after

Status
Not open for further replies.

fr2

Programmer
May 13, 2008
45
0
0
US
I have FormB say with companies info (Add, Edit, Update buttons ..ect). When I load the form, I want to activate the click event for CmdAddNew button

So say I am in FormA ... and I launch

Load FormB

how do I have FormB then automatically call
...CmdAddNew_Click()

Should I have a Public module level variable set in FormB .... so that I can set it in FormA first, ....

then in the form load for FormB test for it ... and launch CmdAddNew_Click() if needed?


 

You can:
Code:
[blue]Private Sub[/blue] Form_Load()
   [blue]Call[/blue] AddNewRecord
[blue]End Sub[/blue]

[blue]Private Sub[/blue] CmdAddNew_Click()
   [blue]Call[/blue] AddNewRecord
[blue]End Sub[/blue]

[blue]Private Sub[/blue] AddNewRecord()
   [green]'Your code to add a new record here[/green]
[blue]End Sub[/blue]

Or you can:
Code:
[blue]Private Sub[/blue] Form_Load()
   CmdAddNew.Value = [blue]True[/blue]
[blue]End Sub[/blue]

Have fun.

---- Andy
 
Hmmmm ...

My command buttons don't have a "value" attribute so I'm not sure how that would work.

In any event, I wouldn't do this in Form_Load because the form is not completely initialized or displayed until Form_Load completes. Try Something like
Code:
Dim StartWithNewAddNew As Boolean

Private Sub Form_Load()
    StartWithNewAddNew = True
End Sub

Private Sub Form_Activate()
    If StartWithNewAddNew Then
        StartWithNewAddNew = False
        CmdAddNew_Click()
    End If
End Sub

in FormB.
 
Hmmmmm....

My VB 6.0 command buttons have .Value:

value.JPG


Have fun.

---- Andy
 
probably vba

-David
2006, 2007 & 2008 Microsoft Most Valuable Professional (VB)
2006 Dell Certified System Professional (CSP)
 
It is often useful to have a Timer on the Form with a short Interval that is used as a "one shot" timer. In the Timer event you disable the Timer control and then peform your "one time startup" action.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top