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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If then Call??

Status
Not open for further replies.

Costefran

Technical User
Jan 2, 2008
197
GB
Hello

Can anyone help

I have a number of after update events on my form that increment a counter called 'Status Count' which is one of the fields on my underlying table

I would like to set up an action on the forms 'on open' event that goes to the particular private sub when status count is a particular value

For example it would go something like

if Status Count =2 then Call Private Sub Control_A_After Update

I am not sure if its a goto or call and am not sure of the coding or syntax so any help would be appreciated

Thanks

 
How are ya Costefran . . .

For starters, try the forms [blue]On Load[/blue] event instead!

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Thanks

I will but still not sure of the code if you could help

 
Something like this (you'll need to change the control names as appropriate):

Code:
Private Sub Form_Load()
    If Me.txtStatusCount.Value = 6 Then
        Call Me.txtControl_A.AfterUpdate
    Else
        'Do something else
    End If
End Sub

Ed Metcalfe.

Please do not feed the trolls.....
 
Costefran said:
[blue]I have a number of after update events on my form that increment a counter called 'Status Count' . . .[/blue]
In such a secnario its typical to make a common routine to handle them all. This also makes it easy as far as troubleshooting is concerned, as all the code is centrally located in one routine. Consider you have the following common routine in the forms code module:
Code:
[blue]Public Sub StatCntHandler(ctlName As String)
   
   If ctlName = "Name1" Then
      [green]'Inc Status Count this way code[/green]
   ElseIf ctlName = "Name2" Then
      [green]'Inc Status Count that way code[/green]
   ElseIf ctlName = "Name3" Then
      [green]'[/green]
   ElseIf ctlName = "NameN" Then
      [green]'Inc Status Count another way code[/green]
   End If

End Sub[/blue]
The call from each [blue]After Update[/blue] event of interest would look like:
Code:
[blue]   Call StatCntHandler("[purple][b][i]ControlName"[/i][/b][/purple])[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
I would advise never calling an event directly. You should make a separate subroutine that is called by the After Update events, and called at whatever other time you feel is appropriate.

The reason to not call events directly is that it makes the purpose of the event ambiguous. An "After Update" event should only occur "after an update". Calling it from anywhere else will make debugging harder.

 
You can try this is you are looking for a case statement

Sub test()
Select Case myvariable
Case 1
' do something
Case 2
' do something
Case 3
' do something
End Select


End Sub



-Me-> All I want is the chance to prove money won't make me happy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top