Solved

How to SetFocus based on a value in a TempVar

Posted on 2011-03-07
3
522 Views
Last Modified: 2012-05-11
Hello. I have a form that displays search results. When the user clicks on a certain record, a macro saves the "ID" value (number) to a TempVar (AccredID_Set).

I then have a macro that opens a new form showing all accreds of the unit the person selected. I would like to SetFocus on the exact record the person selected in the search result form. (So the person doesnt have to go searching through the records again.)

I need to figure out how to set focus based on matching the Accred ID of the new form with the AccredID of the old form. (Saved as a TempVar). I am not finding the syntax or where I should stick the code... (On Load?)

Thanks for the help!

0
Comment
Question by:moot2010
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 35058305
Most of the time you use the Bookmark method if you need to move a form to a specific record:

Dim rst As DAO.Recordset
Set rst = Me.RecordsetClone
rst.FindFirst "YourFieldName=" & Tempvars!YourTempvarName

If Not rst.NoMatch Then Me.Bookmark = rst.Bookmark

Note that assume YOurFieldName is a Numeric datatttype. If it's a Text datatype:

rst.FindFirst "YourFieldName='" & Tempvars!YourTempvarName & "'"

0
 

Author Comment

by:moot2010
ID: 35067926
THANKS! I appreciate your help. I know I didn't ask in my original question, but is there a way to select the whole record? Not just the field?
0
 

Author Closing Comment

by:moot2010
ID: 35067930
The example code provided worked perfectly.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

932 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