By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,441 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,441 IT Pros & Developers. It's quick & easy.

Passing an argument to a subroutine

P: n/a
What is the proper syntax for sending an argument from a form contol to
a subroutine in a module? For instance, from a textbox on a form I call
a module subroutine from the textbox's OnUpdate event. I want to pass
the form's name to the the Module subroutine. What is the proper syntax
for the textbox event to pass the form name and what is the correct
syntax in the module subroutine to accept the form name as an argument?

Thanks
Scott

Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Not sure of OnUpdate event (AfterUpdate ?), but this is a generic example:

Private Sub Textbox_AfterUpdate()
Call MySub(Me.Name)
End Sub

Public Sub MySub(strFormName As String)
MsgBox "My form name is " & strFormName
End Sub
--

Ken Snell
<MS ACCESS MVP>

"Scott" <sm*********@hdgmansur.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
What is the proper syntax for sending an argument from a form contol to
a subroutine in a module? For instance, from a textbox on a form I call
a module subroutine from the textbox's OnUpdate event. I want to pass
the form's name to the the Module subroutine. What is the proper syntax
for the textbox event to pass the form name and what is the correct
syntax in the module subroutine to accept the form name as an argument?

Thanks
Scott

Nov 13 '05 #2

P: n/a
rkc
Scott wrote:
Thanks. That works well. However, from within the Public Sub, I want to
loop through specific controls (textboxes, comboboxes, etc.). When I do
that using the strfrmName variable I get an error that tells me it can
only loop through a specific entity within a collection. - Presumably
it wants the code to specify Forms!strfrmName. The code loops through
all the text controls to see if they have data before setting the
"Done" button's enabled property to "True." The code is hanging up on
Line (02). I assume it will also choke on Line (10).

Public Sub Check_Controls(strfrmName As String)

Dim ctl As Control
Dim btnStatus As Boolean

Line (01) btnStatus = True
Line (02) For Each ctl In strfrmName
Line (03) If ctl.ControlType <> acCommandButton Or ctl.ControlType <>
acLabel
Line (04) Then
Line (05) If IsEmpty(ctl) Then
Line (06) btnStatus = False
Line (07) End If
Line (08) End If
Line (09) Next ctl

Line (10) strfrmName cmdDone.Enabled = btnStatus

End Sub

Thanks for any help!
Scott


Just pass the form object itself.

Call Check_Controls(Me)

Public Sub Check_Controls(frm As Access.Form)
'---
For Each ctl In frm
'---
End Sub

Lookup the IsEmpty function in the help file.

Nov 13 '05 #3

P: n/a
Thanks. That's it.
Scott

Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.