calling a sub or function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two forms.. when i click a button on the first form I would like to
call a sub in the second form. How do i do this?

Thanks in advance

Pip'n
 
It is generally not a good idea to call a sub from a class module. If you
want to use a sub from more than one form, put the sub in a regular module
and call it from both forms.

ed
 
Hi, Pip'n.
I have two forms.. when i click a button on the first form I would like to
call a sub in the second form. How do i do this?

The second form must also be open, and the subroutine in the second form
must be public, not private. In the following example of code for a button
on the first form, the second form is named frmSales, and the subroutine
being called is myProc.

' * * * * Start Code * * * *

Private Sub CallProcBtn_Click()

On Error GoTo ErrHandler

Dim sFormName As String
Dim sProcName As String

sFormName = "frmSales"
sProcName = "myProc"
CallByName Forms(sFormName), sProcName, VbMethod

Exit Sub

ErrHandler:

MsgBox "Error in CallProcBtn_Click( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub ' CallProcBtn_Click( )

' * * * * End Code * * * *


HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are (e-mail address removed) and (e-mail address removed)

- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts as "Answers,"
so that all may benefit by filtering on "Answered questions" and quickly
finding the right answers to similar questions. Remember that questions
answered the quickest are often from those who have a history of rewarding
the contributors who have taken the time to answer questions correctly.
 
Back
Top