Moving between forms

J

Jwil

Hello,

I've made some buttons to navigate between forms. All the forms are related
so I would like to stay on the current record that is being displayed when
moving between the forms. Can someone please help me with this? I've tried
the GoToRecord function and in the offset put =[Forms]![EntryForm].[Record
ID] but it says that the expression is the wrong data type.

Thank you
 
J

Jeanette Cunningham

DoCmd.OpenForm, , , "[KeyField] = " & Me.[KeyField]

is one way to open a form at a particular record.

Replace KeyField with your field name.
You only need the square brackets if there are spaces in the field name.
If KeyField is a text data type, use

"[KeyField] = """ & Me.[KeyField] & """"


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
J

Jwil

Jeanette Cunningham said:
DoCmd.OpenForm, , , "[KeyField] = " & Me.[KeyField]

Thank you Jeanette. It is going to the record ok but it is filtering the
records so that only that particular record is shown. And when you press the
"filtered" button to unfilter the records it goes back to record 1. Is there
a way to do this without it filtering the records so that you can still move
back and forth between the records?
 
J

Jeanette Cunningham

Yes, you can do open form using open args, then apply a filter.

DoCmdOpenForm "FormName", , , , , , Me.[KeyField]

ON the form being opened, put a sub that does the filtering.

Private Sub FilterMe
Me.Filter = "[KeyField] = " & Me.OpenArgs
Me.FilterOn = True
End Sub

Call the FilterMe sub on the form's load event.


You can also use FindFirst instead of applying a filter.
FindFirst will show all the records, and if you make the record selectors
visible, the FindFirst code will move the arrow to the record that matches
the open args.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Jwil said:
Jeanette Cunningham said:
DoCmd.OpenForm, , , "[KeyField] = " & Me.[KeyField]

Thank you Jeanette. It is going to the record ok but it is filtering the
records so that only that particular record is shown. And when you press
the
"filtered" button to unfilter the records it goes back to record 1. Is
there
a way to do this without it filtering the records so that you can still
move
back and forth between the records?
 
J

Jwil

Jeanette Cunningham said:
Yes, you can do open form using open args, then apply a filter.

DoCmdOpenForm "FormName", , , , , , Me.[KeyField]

ON the form being opened, put a sub that does the filtering.

Private Sub FilterMe
Me.Filter = "[KeyField] = " & Me.OpenArgs
Me.FilterOn = True
End Sub

Call the FilterMe sub on the form's load event.


You can also use FindFirst instead of applying a filter.
FindFirst will show all the records, and if you make the record selectors
visible, the FindFirst code will move the arrow to the record that matches
the open args.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
Jeanette,

I'm still having trouble . I tried the first method. It opened the form but
when I put the second code in the form's load event it just turned the filter
on. The code has Me.FilterOn = True so that seems to make sense. I would
like the filter off but to go to the record. I tried to figure out the
second method but I couldn't. I'm a beginner so could you please help me
with the findfirst method?

Thank you
 
J

Jeanette Cunningham

To be a bit more clear that we are both talking about the same thing.
Do you want to open the form with all its records showing?
Then you want to see the record selector arrow on the row that matches the
ID from the calling form( the one that opens this one)?

To use FindFirst

Private Sub FindMatchingRecord
With Me.RecordsetClone
.FindFirst "[KeyField] = " & Me.OpenArgs
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End Sub


In the form's load event
Call FindMatchingRecord


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Jwil said:
Jeanette Cunningham said:
Yes, you can do open form using open args, then apply a filter.

DoCmdOpenForm "FormName", , , , , , Me.[KeyField]

ON the form being opened, put a sub that does the filtering.

Private Sub FilterMe
Me.Filter = "[KeyField] = " & Me.OpenArgs
Me.FilterOn = True
End Sub

Call the FilterMe sub on the form's load event.


You can also use FindFirst instead of applying a filter.
FindFirst will show all the records, and if you make the record selectors
visible, the FindFirst code will move the arrow to the record that
matches
the open args.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
Jeanette,

I'm still having trouble . I tried the first method. It opened the form
but
when I put the second code in the form's load event it just turned the
filter
on. The code has Me.FilterOn = True so that seems to make sense. I would
like the filter off but to go to the record. I tried to figure out the
second method but I couldn't. I'm a beginner so could you please help me
with the findfirst method?

Thank you
 
J

Jwil

Jeanette Cunningham said:
To be a bit more clear that we are both talking about the same thing.
Do you want to open the form with all its records showing?
Then you want to see the record selector arrow on the row that matches the
ID from the calling form( the one that opens this one)?

To use FindFirst

Private Sub FindMatchingRecord
With Me.RecordsetClone
.FindFirst "[KeyField] = " & Me.OpenArgs
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End Sub


In the form's load event
Call FindMatchingRecord


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
Hi Jeanette,

I just came back in town and tried your code and it works perfectly. Thank
you very much.
 
D

De Jager

Jwil said:
Hello,

I've made some buttons to navigate between forms. All the forms are
related
so I would like to stay on the current record that is being displayed when
moving between the forms. Can someone please help me with this? I've tried
the GoToRecord function and in the offset put =[Forms]![EntryForm].[Record
ID] but it says that the expression is the wrong data type.

Thank you
 
J

joelgeraldine

:!:!:!

Jwil said:
Jeanette Cunningham said:
To be a bit more clear that we are both talking about the same thing.
Do you want to open the form with all its records showing?
Then you want to see the record selector arrow on the row that matches
the
ID from the calling form( the one that opens this one)?

To use FindFirst

Private Sub FindMatchingRecord
With Me.RecordsetClone
.FindFirst "[KeyField] = " & Me.OpenArgs
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End Sub


In the form's load event
Call FindMatchingRecord


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
Hi Jeanette,

I just came back in town and tried your code and it works perfectly.
Thank
you very much.
 

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

Similar Threads

Form Navigation 1
Open Form Code Error 5
Moving Between Records 2
Search Upon Open 13
Sub Forms 3
RECORDS IN FORMS 1
Access 2000 Forms: Disable Scroll Wheel through Records 2
Serious Performance Problem 14

Top