Solved

Access VBA call subroutine that is in a subform

Posted on 2012-03-16
8
702 Views
Last Modified: 2012-03-16
I created a subroutine that is located in a subform.
What's the syntax to call it from another [unrelated] form? I've tried everything I could think of.

Forms!MainForm!Subform.Form.GoToId (540)
0
Comment
Question by:etech0
  • 4
  • 3
8 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
what is the sub routine ? post it here

make the sub Public instead of Private
0
 
LVL 10

Author Comment

by:etech0
Comment Utility
Public Sub GoToId(ByVal RecID As Integer)
Dim rs As dao.Recordset

' set it to a clone of the form's recordset so that whatever you do doesn't affect the form just yet
Set rs = Me.RecordsetClone

rs.FindFirst "[id]=" & RecID

' if there's a match, set the form's bookmark to that of the rs' bookmark
If Not rs.NoMatch Then
    Me.Bookmark = rs.Bookmark
End If

Set rs = Nothing
End Sub
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
what are the actual names of the
main form
subform
subform control
0
 
LVL 10

Author Comment

by:etech0
Comment Utility
CatWebWork2F
CatWebWork2SummaryF

What control? The ID field is called ID.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 10

Author Comment

by:etech0
Comment Utility
The macro is in CatWebWork2SummaryF, and I'm trying to call it from another form entirely.
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 450 total points
Comment Utility
try this

call Form_CatWebWork2SummaryF.GoToId (540)
0
 
LVL 9

Assisted Solution

by:macarrillo1
macarrillo1 earned 50 total points
Comment Utility
I would remake this subroutine into a public subroutine in your code module. Then call as needed.

Public SubGoToId(ByVal RecID As Integer, fName as object)

' set it to a clone of the form's recordset so that whatever you do doesn't affect the form just yet
Set rs = fName.RecordsetClone

rs.FindFirst "[id]=" & RecID

' if there's a match, set the form's bookmark to that of the rs' bookmark
If Not rs.NoMatch Then
    fName.Bookmark = rs.Bookmark
End If

Set rs = Nothing
End Sub
0
 
LVL 10

Author Closing Comment

by:etech0
Comment Utility
Whew - thanks!
macarrillo1: interesting idea, I'll keep it in mind.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now