Running a module

  • Thread starter Thread starter John
  • Start date Start date
J

John

I'm sure I'm not using the correct terminology, but
here's my question.

I have declared a public function. I have an afterupdate
event that triggers, and I want to execute the function
if a certain criteria is met, otherwise I want to go on
to do other things. I'm sure it's simple, but I usually
just use my public functions by putting =FunctionName
("data") in the event.

e.g.

I have a textbox. If the textbox = "s", I want it to
execute the function, otherwise I want to go ahead and
continue. Here's what I have:

Private Sub txtClient_AfterUpdate()

On Error GoTo err_clientUpdate

DoCmd.GoToControl "txtClientID"
DoCmd.FindRecord [txtClient]
DoCmd.GoToControl "txtClientID"

'Here's the part I need help with:
If txtClient="s"
run function SearchForm
resume exit_ClientUpdate
End If

If txtClientID <> txtClient Then
Forms!dlgerror.Caption = "Invalid Client Number"
Forms!dlgerror!txtTitle = "Invalid Client Number"
Forms!dlgerror!txtError = "The client number you
_entered does not exist. If you wish to add a
_new client, simply click the 'New' button. You
_can either click the 'Search' button or type
_an 's' into the clientID field to search for a
_specific client."
Forms!dlgerror.Visible = True
End If

exit_ClientUpdate:
Exit Sub

err_clientUpdate:
MsgBox "You have no clients currently entered into
the system.", , "Error!"
Exit Sub

End Sub

Thanks,

John
 
Hi John,

First and foremost, Make sure that the function you want
to call is contained within a module (from the VB Editor
go to insert>module). There are a few different ways to
call a function. My personal choice is:

Call module_name.functionName(arguments here)

or

functionName arguments_here

Regards,
Jen
 
John,
That is too much code
see comments inline
It would help to see the code in the function

HS
Private Sub txtClient_AfterUpdate()

On Error GoTo err_clientUpdate

DoCmd.GoToControl "txtClientID"
DoCmd.FindRecord [txtClient]
DoCmd.GoToControl "txtClientID"
these lines are not needed


'Here's the part I need help with:
If me.txtClient="s"
run function SearchForm
a function has a return value. A sub does not return a value
if you do not want a return value, change it to a sub routine.
resume exit_ClientUpdate
End If
If txtClientID <> txtClient Then
Forms!dlgerror.Caption = "Invalid Client Number"
Forms!dlgerror!txtTitle = "Invalid Client Number"
Forms!dlgerror!txtError = "The client number you
_entered does not exist. If you wish to add a
_new client, simply click the 'New' button. You
_can either click the 'Search' button or type
_an 's' into the clientID field to search for a
_specific client."
Forms!dlgerror.Visible = True

What is the purpose of this?
is your sub/function changing the value of ClientID?
are you requerying the form in this function.
This is a bit convoluted.
 
It does not have to be in a (different) module. it can be in this form's
code module.
The limitation would be that it may not available to other forms and objects

HS

Jen said:
Hi John,

First and foremost, Make sure that the function you want
to call is contained within a module (from the VB Editor
go to insert>module). There are a few different ways to
call a function. My personal choice is:

Call module_name.functionName(arguments here)

or

functionName arguments_here

Regards,
Jen
-----Original Message-----
I'm sure I'm not using the correct terminology, but
here's my question.

I have declared a public function. I have an afterupdate
event that triggers, and I want to execute the function
if a certain criteria is met, otherwise I want to go on
to do other things. I'm sure it's simple, but I usually
just use my public functions by putting =FunctionName
("data") in the event.

e.g.

I have a textbox. If the textbox = "s", I want it to
execute the function, otherwise I want to go ahead and
continue. Here's what I have:

Private Sub txtClient_AfterUpdate()

On Error GoTo err_clientUpdate

DoCmd.GoToControl "txtClientID"
DoCmd.FindRecord [txtClient]
DoCmd.GoToControl "txtClientID"

'Here's the part I need help with:
If txtClient="s"
run function SearchForm
resume exit_ClientUpdate
End If

If txtClientID <> txtClient Then
Forms!dlgerror.Caption = "Invalid Client Number"
Forms!dlgerror!txtTitle = "Invalid Client Number"
Forms!dlgerror!txtError = "The client number you
_entered does not exist. If you wish to add a
_new client, simply click the 'New' button. You
_can either click the 'Search' button or type
_an 's' into the clientID field to search for a
_specific client."
Forms!dlgerror.Visible = True
End If

exit_ClientUpdate:
Exit Sub

err_clientUpdate:
MsgBox "You have no clients currently entered into
the system.", , "Error!"
Exit Sub

End Sub

Thanks,

John

.
 
Although my question has been answered, to clarify what
the sub function in question is doing:

There is a form for client information which is read-only
for non-clerical staff. After the field txtClient is
updated (this is an unbound text box) I search for that
record (perhaps there's a quicker way to do this than
moving into the bound txtClientID control?). If that
record is not found, a custom error dialog form appears
with text specific to the form with the error. If that
record is found, it goes to that record. If the user
enters an "s" into the field txtClient it opens up a form
for searching.

John
 
Back
Top