Go to a Specific Form

D

Debbie

I have created a table of records. When a record is clicked, I want the
specific form for that record to open. The command I have now, Open Form,
opens a new, blank form. Any thoughts on how to get the specific form to
open. This is driving me crazy!!!!
 
A

Arvin Meyer [MVP]

You can build a datasheet of your table with an open form action, but you
cannot run code from a table. There is a button wizard which will write the
code for you to open a specific record. Just copy all the code with the
exception of the top and bottom lines and put it in the DblClick event of
the ID field in your datasheet form.
 
J

Jeff Boyce

Debbie

We aren't there. We can't see how you've done this.

What do you mean "when a record is clicked"? Where is it "clicked"?

From your description, it sounds like you have a different ("specific") form
for each record. Or do you mean that you'd like to see the specific RECORD
displayed, each/all on the same form?

More info, please...

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
R

roccogrand

Debbie,

I will assume that you have a form and will be selecting one of the records
in the table using the form.

Now create a second form with the data from your table and in the format of
interest.

Place a Command button on the first form and add this code to the Click Event.

---------------------

Private Sub cmdViewThisRecord_Click()
'Access will give your subroutine a name initially
'I have named this command ViewThisRecord

'Have an out in case the code throws an error
On Error GoTo Err_cmdViewThisRecord_Click

'Declare a couple variables
Dim stDocName As String
Dim stLinkCriteria As String

'frmMySecondForm is the name that you give to the new form
stDocName = "frmMySecondForm"

'MyName is the name of the field that links the two forms
'MyName can be the ID field (autonumber) or another field's name

stLinkCriteria = "[MyName]=" & "'" & Me![MyName] & "'"

'Don't leave out any of the parentheses, single or double

'The next line opens the second form
'and displays the record with the same field name

DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdViewThisRecord_Click:
Exit Sub

'These lines trap errors
Err_cmdViewThisRecord_Click:
MsgBox Err.Description
Resume Exit_cmdViewThisRecord_Click

End Sub

-----The easiest way to do this however is to use the form wizard.

Open your first form
Switch to Design View
Draw a command button
Select Form Operations
Click Open Form
Next
select the second form in the list of available forms
Next
Click Open the form and find specific data to display
Next
Match a field in both the left and right panes by clicking them
Click the <-> button
Next
Give the button a name or select an image
Finish

Now when these actions don't work: It is when there is no match for the
fields sourcing the two forms.

I hope this helps.

LDN
 

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