Need a macro to open a certain record from a form

L

lifesbrink

Currently, I have 2 forms available. The one form has a query, and th
other is for editing/adding. I need a macro that will run when I pres
SPACE on a record's line that opens the selected record in the editin
form that I have set up.

Basically, I am linking the 2 forms together. I have it set up where
can open the other form, but not to the selected record. I know ther
are other methods, but my boss demands this method be used, so I hav
no other choice. I only recently started using Access, so much of th
terminology is foreign to me, so please explain any specific macros
queries, SQL statements (if any) or whatnot to me if you use them
 
A

Arvin Meyer [MVP]

The line of code you need is:

DoCmd.OpenForm "SecondFormName" ,,, "ID =" & Me.txtID

where SecondFormName is the name of the form you want to open, ID is the
name of the primary key or unique index, and txtID is the name of the
textbox on the current form that hold the ID field.

You will need to use a command button or a mouse click event on a control on
your form to accomplish your goal, otherwise the Spacebar would need to be
remapped and that would mean you couldn't use it for anything else on the
form.
 
L

lifesbrink

Here is some more info that is similar to what I want:
_______________________________
A valid SQL WHERE clause (WHERE clause: The part of an SQL statemen
that specifies which records to retrieve.) (without the word WHERE) o
expression (expression: Any combination of mathematical or logica
operators, constants, functions, and names of fields, controls, an
properties that evaluates to a single value. Expressions can perfor
calculations, manipulate characters, or test data.) that Access uses t
select records from the form's underlying table or query. If you selec
a filter with the Filter Name argument, Access applies this WHER
clause to the results of the filter.
To open a form and restrict its records to those specified by the valu
of a control on another form, use the following expression:

[fieldname] = Forms![formname]![controlname on other form]

Replace fieldname with the name of a field in the underlying table o
query of the form you want to open. Replace formname and controlname o
other form with the name of the other form and the control on the othe
form that contains the value you want records in the first form t
match.
_____________________________________________
To note of which forms I have:
Main Display or Primary Form (Fields - Indate, Subject, Status)
Task List or Opening Form (Same Fields

I tried entering in the expression [Indate] = Forms![Mai
Display]![Indate]
That just generated errors though. I really need this done soon
 
L

lifesbrink

Well that gets me closer, except, how do I find this primary key ID?
Also, where do I enter this line in
 
A

Arvin Meyer [MVP]

Look at your table structure, and at the indexes. Find the names which you
have used. You may not have a primary key or unique index, in which case you
won't be able to open to a specific record.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top