Default Record

A

AccessTool

Hi,
How can I set a default value for the record that is
loaded when I open a form? For example, if the current
form is on Record 6 and I click a button that opens a new
form (with related data), I want that form to load on
Record 6 as well rather than Record 1. Is this possible
in Access97? Thanks.
 
K

Kevin Sprinkel

Do you really want to open a specific record number, or to
rather match the primary key?
The strategy is to use a WHERE clause in the OpenForm
method. The command button wizard will create the code
for you. The following opens a form named
frmManufacturers when pressed from frmProducts, showing
the name, address, etc. of the product manufacturer
matching the key field MfrID.

HTH
Kevin Sprinkel

Private Sub Command22_Click()
On Error GoTo Err_Command22_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmManufacturers"

stLinkCriteria = "[MfrID]=" & Me![cboMfr]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command22_Click:
Exit Sub

Err_Command22_Click:
MsgBox Err.Description
Resume Exit_Command22_Click

End Sub
 

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