How to open a form at a specific record

  • Thread starter Thread starter H.Ockhuysen
  • Start date Start date
H

H.Ockhuysen

As an maatuer I have managed to make tabel with adress data
I also made a form based on this table.
However, now I want to be able to open the form at a specific record when
workin in the table
I so far have tried to work with macro's but the form either opens blank or
always at the first record.
please help
 
You can have the form open to a specific record, but you should not be
working directly in the table.

Which record? What do you want to tell Access to go to that record? When
the form starts? After it is open?
 
The form shows all the fields. I want it to open at a specific record,so I
can enter data in certain fields
 
Put the details into the Where argument for OpenForm:
DoCmd.OpenForm "FormName", , , "MainID = " & Me.MainID

You say you want "to open at a specific record". You need to tell Access
which record. If you have a form open, and want to open another form to a
record that has something in common with the current record on the open
form, the above should work if you substitute your form name and the actual
field names, provided MainID is a number field.

The problem with suggesting how to go about this is that you have not
provided any details. Try describing in non-database terms what you hope to
do. Also, some desciription of your database would help.
 
Ok
I'll try. I have a table with adress-details and such. The form shows all
these fields.
Say I select record 25. I then want to click on the form-button and have the
form open at record 25.
I hope this is more clear.
btw I appreciate your help very much
harry Ockhuysen
 
You cannot run an event from the table. You could create a form (I will
call it frmContact) in datasheet view, which resembles a table. I will
assume this is a Contacts database, that the form you want to open is
frmMain, and that the number 25 (in your example) is in the ContactID field.
The text box bound to ContactID could have as its Click event:
DoCmd.OpenForm "frmMain", , , "ContactID = " & Me.ContactID
If ContactID is a text field:
DoCmd.OpenForm "frmMain", , , "ContactID = """ & Me.ContactID & """"
This will open frmMain to show only records in which ContactID is the same
as ContactID on frmContact.

If you want to show all records you can use the Apply Filter/Remove Filter
toolbar button, or you can have a command button with the Click event code:
Me.FilterOn = False
or, to toggle the filter property:
Me.FilterOn = Not Me.FilterOn

It is also possible to open frmMain so that it loads all records, but goes
to a specific record. In the text box Click event as described above:

Dim strArgs as String
strArgs = "ContactID = " & Me.ContactID

DoCmd.OpenForm "frmMain", OpenArgs:=strArgs

Then, in the Load event for frmMain:

If Len(Me.OpenArgs) > 0 Then
With Me.RecordsetClone
.FindFirst Me.OpenArgs
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
Else ' i.e. if form is opened directly rather than from frmContacts
Me.SomeControl.SetFocus
End If

SomeControl is a control on frmMain. You do not need to set focus as I have
shown, but you may want to do something if the form is opened directly
rather than from frmContacts. If you will always open frmMain from
frmContacts you do not need the If:

With Me.RecordsetClone
.FindFirst Me.OpenArgs
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
 
Back
Top