Open Form On Same Record

  • Thread starter Thread starter JamesJ
  • Start date Start date
J

JamesJ

I want to have a command button, on form frmDvd, open form frmDvdEdit
to the same record that is the current record on frmDvd. Also, I want to
be able to 'browse' using the frmDvdEdit (records not filtered). My Primary
Key is DvdMovieID.

Thanks,
James
 
Have your command button call a macro opening second form and action
FindRecord in second form matching the DvdMovieID in first form.
 
Hi James

Normally you would use the WhereCondition argument to create a filter as the
second form opens:

DoCmd.OpenForm "frmDvdEdit", _
WhereCondition:="DvdMovieID=" & Me!DvdMovieID

However, this will give you only one record so, instead, pass the ID through
OpenArgs and have the Form_Load event procedure navigate to the initial
record:

DoCmd.OpenForm "frmDvdEdit", OpenArgs:=Me.DvdMovieID

.... and in frmDvdEdit.Form_Load:

If Not IsNull(Me.OpenArgs) Then
With Me.RecordsetClone
.FindFirst "DvdMovieID=" & Me.OpenArgs
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End If
 
I'll give it a shot.

KARL DEWEY said:
Have your command button call a macro opening second form and action
FindRecord in second form matching the DvdMovieID in first form.
 
I'll try it.

Thanks,
James

Graham Mandeno said:
Hi James

Normally you would use the WhereCondition argument to create a filter as
the second form opens:

DoCmd.OpenForm "frmDvdEdit", _
WhereCondition:="DvdMovieID=" & Me!DvdMovieID

However, this will give you only one record so, instead, pass the ID
through OpenArgs and have the Form_Load event procedure navigate to the
initial record:

DoCmd.OpenForm "frmDvdEdit", OpenArgs:=Me.DvdMovieID

... and in frmDvdEdit.Form_Load:

If Not IsNull(Me.OpenArgs) Then
With Me.RecordsetClone
.FindFirst "DvdMovieID=" & Me.OpenArgs
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End If
--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

JamesJ said:
I want to have a command button, on form frmDvd, open form frmDvdEdit
to the same record that is the current record on frmDvd. Also, I want to
be able to 'browse' using the frmDvdEdit (records not filtered). My
Primary
Key is DvdMovieID.

Thanks,
James
 
frmDvdEdit continues to open on the first record.
I put the DoCmd on the OnClick of the Command Button of frmDvd. And
the other code in the OnLoad of DvdEdit.

Can't understand,
James


Graham Mandeno said:
Hi James

Normally you would use the WhereCondition argument to create a filter as
the second form opens:

DoCmd.OpenForm "frmDvdEdit", _
WhereCondition:="DvdMovieID=" & Me!DvdMovieID

However, this will give you only one record so, instead, pass the ID
through OpenArgs and have the Form_Load event procedure navigate to the
initial record:

DoCmd.OpenForm "frmDvdEdit", OpenArgs:=Me.DvdMovieID

... and in frmDvdEdit.Form_Load:

If Not IsNull(Me.OpenArgs) Then
With Me.RecordsetClone
.FindFirst "DvdMovieID=" & Me.OpenArgs
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End If
--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

JamesJ said:
I want to have a command button, on form frmDvd, open form frmDvdEdit
to the same record that is the current record on frmDvd. Also, I want to
be able to 'browse' using the frmDvdEdit (records not filtered). My
Primary
Key is DvdMovieID.

Thanks,
James
 
Hi James

Is your Form_Load procedure being executed? The "On Load" cell in the
form's property sheet should say [Event Procedure].

Try temporarily inserting a Stop command just before If Not IsNull...

Then the code execution will break there and you can step through it line by
line with F8.

You can also examine values in the Immediate window to verify that things
are going to plan. For example:
?Me.OpenArgs
will show you what value was passed to the form.
--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

JamesJ said:
frmDvdEdit continues to open on the first record.
I put the DoCmd on the OnClick of the Command Button of frmDvd. And
the other code in the OnLoad of DvdEdit.

Can't understand,
James


Graham Mandeno said:
Hi James

Normally you would use the WhereCondition argument to create a filter as
the second form opens:

DoCmd.OpenForm "frmDvdEdit", _
WhereCondition:="DvdMovieID=" & Me!DvdMovieID

However, this will give you only one record so, instead, pass the ID
through OpenArgs and have the Form_Load event procedure navigate to the
initial record:

DoCmd.OpenForm "frmDvdEdit", OpenArgs:=Me.DvdMovieID

... and in frmDvdEdit.Form_Load:

If Not IsNull(Me.OpenArgs) Then
With Me.RecordsetClone
.FindFirst "DvdMovieID=" & Me.OpenArgs
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End If
--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

JamesJ said:
I want to have a command button, on form frmDvd, open form frmDvdEdit
to the same record that is the current record on frmDvd. Also, I want to
be able to 'browse' using the frmDvdEdit (records not filtered). My
Primary
Key is DvdMovieID.

Thanks,
James
 
I found I didn't put the dot before Bookmark.
I tried with another form(s) and it didn't work. Had an extra double quote.
Don't know why I didn't get an error.
I guess copying and pasting would have been the way to do it.
I can't seem to type one word without misspelling.

But, all seems well now.

Thanks much.
James

Graham Mandeno said:
Hi James

Is your Form_Load procedure being executed? The "On Load" cell in the
form's property sheet should say [Event Procedure].

Try temporarily inserting a Stop command just before If Not IsNull...

Then the code execution will break there and you can step through it line
by line with F8.

You can also examine values in the Immediate window to verify that things
are going to plan. For example:
?Me.OpenArgs
will show you what value was passed to the form.
--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

JamesJ said:
frmDvdEdit continues to open on the first record.
I put the DoCmd on the OnClick of the Command Button of frmDvd. And
the other code in the OnLoad of DvdEdit.

Can't understand,
James


Graham Mandeno said:
Hi James

Normally you would use the WhereCondition argument to create a filter as
the second form opens:

DoCmd.OpenForm "frmDvdEdit", _
WhereCondition:="DvdMovieID=" & Me!DvdMovieID

However, this will give you only one record so, instead, pass the ID
through OpenArgs and have the Form_Load event procedure navigate to the
initial record:

DoCmd.OpenForm "frmDvdEdit", OpenArgs:=Me.DvdMovieID

... and in frmDvdEdit.Form_Load:

If Not IsNull(Me.OpenArgs) Then
With Me.RecordsetClone
.FindFirst "DvdMovieID=" & Me.OpenArgs
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End If
--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

I want to have a command button, on form frmDvd, open form frmDvdEdit
to the same record that is the current record on frmDvd. Also, I want
to
be able to 'browse' using the frmDvdEdit (records not filtered). My
Primary
Key is DvdMovieID.

Thanks,
James
 
Hi James

That's great! I'm glad you got it working :-)

You should ensure that you have "Option Explicit" at the top of every single
one of your modules. This forces you to explicitly declare any variables
you use and *greatly* reduces the amount of hair-tearing in tracking down
problems that are caused by simple typos like this.

With Option Explicit, your code would not have run at all. Instead
"Bookmark" would have been highlighted as an "undeclared variable" and you
would have spotted the problem immediately.

You should also go to Tools > Options and check the box "Require variable
declaration". That way, "Option Explicit" will automatically be inserted
into any new module you create. (You will need to do existing modules
manually though.)
--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

JamesJ said:
I found I didn't put the dot before Bookmark.
I tried with another form(s) and it didn't work. Had an extra double
quote.
Don't know why I didn't get an error.
I guess copying and pasting would have been the way to do it.
I can't seem to type one word without misspelling.

But, all seems well now.

Thanks much.
James

Graham Mandeno said:
Hi James

Is your Form_Load procedure being executed? The "On Load" cell in the
form's property sheet should say [Event Procedure].

Try temporarily inserting a Stop command just before If Not IsNull...

Then the code execution will break there and you can step through it line
by line with F8.

You can also examine values in the Immediate window to verify that things
are going to plan. For example:
?Me.OpenArgs
will show you what value was passed to the form.
--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

JamesJ said:
frmDvdEdit continues to open on the first record.
I put the DoCmd on the OnClick of the Command Button of frmDvd. And
the other code in the OnLoad of DvdEdit.

Can't understand,
James


Hi James

Normally you would use the WhereCondition argument to create a filter
as the second form opens:

DoCmd.OpenForm "frmDvdEdit", _
WhereCondition:="DvdMovieID=" & Me!DvdMovieID

However, this will give you only one record so, instead, pass the ID
through OpenArgs and have the Form_Load event procedure navigate to the
initial record:

DoCmd.OpenForm "frmDvdEdit", OpenArgs:=Me.DvdMovieID

... and in frmDvdEdit.Form_Load:

If Not IsNull(Me.OpenArgs) Then
With Me.RecordsetClone
.FindFirst "DvdMovieID=" & Me.OpenArgs
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End If
--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

I want to have a command button, on form frmDvd, open form frmDvdEdit
to the same record that is the current record on frmDvd. Also, I want
to
be able to 'browse' using the frmDvdEdit (records not filtered). My
Primary
Key is DvdMovieID.

Thanks,
James
 
Found that out. By default Option Explicit isn't there.

Thanks again,
James

Graham Mandeno said:
Hi James

That's great! I'm glad you got it working :-)

You should ensure that you have "Option Explicit" at the top of every
single one of your modules. This forces you to explicitly declare any
variables you use and *greatly* reduces the amount of hair-tearing in
tracking down problems that are caused by simple typos like this.

With Option Explicit, your code would not have run at all. Instead
"Bookmark" would have been highlighted as an "undeclared variable" and you
would have spotted the problem immediately.

You should also go to Tools > Options and check the box "Require variable
declaration". That way, "Option Explicit" will automatically be inserted
into any new module you create. (You will need to do existing modules
manually though.)
--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

JamesJ said:
I found I didn't put the dot before Bookmark.
I tried with another form(s) and it didn't work. Had an extra double
quote.
Don't know why I didn't get an error.
I guess copying and pasting would have been the way to do it.
I can't seem to type one word without misspelling.

But, all seems well now.

Thanks much.
James

Graham Mandeno said:
Hi James

Is your Form_Load procedure being executed? The "On Load" cell in the
form's property sheet should say [Event Procedure].

Try temporarily inserting a Stop command just before If Not IsNull...

Then the code execution will break there and you can step through it
line by line with F8.

You can also examine values in the Immediate window to verify that
things are going to plan. For example:
?Me.OpenArgs
will show you what value was passed to the form.
--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

frmDvdEdit continues to open on the first record.
I put the DoCmd on the OnClick of the Command Button of frmDvd. And
the other code in the OnLoad of DvdEdit.

Can't understand,
James


Hi James

Normally you would use the WhereCondition argument to create a filter
as the second form opens:

DoCmd.OpenForm "frmDvdEdit", _
WhereCondition:="DvdMovieID=" & Me!DvdMovieID

However, this will give you only one record so, instead, pass the ID
through OpenArgs and have the Form_Load event procedure navigate to
the initial record:

DoCmd.OpenForm "frmDvdEdit", OpenArgs:=Me.DvdMovieID

... and in frmDvdEdit.Form_Load:

If Not IsNull(Me.OpenArgs) Then
With Me.RecordsetClone
.FindFirst "DvdMovieID=" & Me.OpenArgs
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End If
--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

I want to have a command button, on form frmDvd, open form frmDvdEdit
to the same record that is the current record on frmDvd. Also, I want
to
be able to 'browse' using the frmDvdEdit (records not filtered). My
Primary
Key is DvdMovieID.

Thanks,
James
 
Back
Top