Synchronizing two forms

  • Thread starter Thread starter Fred Boer
  • Start date Start date
F

Fred Boer

Hello!

I have two related forms: Frm_LibraryDataEdit and Frm_LibraryDataFilter. The
first displays book information for editing. The second displays book
information for searching. There is a command button on each form which will
open the related form, and position the related form to the same record as
the calling form. This works fine, using OpenArgs, if the form being called
is not already open.

However, if the form being called *is* already open, I can't seem to
synchronize it to the calling form. I include the code below. I have
confirmed that the IsLoaded( ) function is returning the proper value, and
the the correct Book_ID is available to the FindFirst command.



1. If I am calling a form which is already open, is "DoCmd.OpenForm" the
appropriate command?
2. What is wrong with my code? :(

Thanks!
Fred Boer

(Isloaded( ) is the standard function from Northwind Traders.)

If ISLOADED("Frm_LibraryDataFilter") Then

DoCmd.OpenForm ("Frm_LibraryDataFilter")
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Book_ID] = " & _
Forms!Frm_LibraryDataEdit!txtBook_ID
Me.Bookmark = rs.Bookmark
Else

DoCmd.OpenForm ( _
"Frm_LibraryDataFilter"), _
OpenArgs:="Book_ID= " & Me!txtBook_ID

End If
 
Fred said:
I have two related forms: Frm_LibraryDataEdit and Frm_LibraryDataFilter. The
first displays book information for editing. The second displays book
information for searching. There is a command button on each form which will
open the related form, and position the related form to the same record as
the calling form. This works fine, using OpenArgs, if the form being called
is not already open.

However, if the form being called *is* already open, I can't seem to
synchronize it to the calling form. I include the code below. I have
confirmed that the IsLoaded( ) function is returning the proper value, and
the the correct Book_ID is available to the FindFirst command.



1. If I am calling a form which is already open, is "DoCmd.OpenForm" the
appropriate command?

That will give the focus to the form.

2. What is wrong with my code? :(

(Isloaded( ) is the standard function from Northwind Traders.)

If ISLOADED("Frm_LibraryDataFilter") Then

DoCmd.OpenForm ("Frm_LibraryDataFilter")
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Book_ID] = " & _
Forms!Frm_LibraryDataEdit!txtBook_ID
Me.Bookmark = rs.Bookmark
Else

I think you have the Form objects mixed up here. Me refers
to the calling form, but you want to find the corresponding
record in the called form:

DoCmd.OpenForm ("Frm_LibraryDataFilter")
With Forms("Frm_LibraryDataFilter").RecordsetClone
.FindFirst "[Book_ID] = " & Me.txtBook_ID
If Not .NoMatch Then Me.Bookmark = .Bookmark
End With
Else
 
Hi Marsh!

Thanks! I see what you mean. In my own boneheaded logic I thought.. ok.. did
the command open form.. now the next statement will apply to that open
form... <sheesh!>

However, I am getting an error with your suggestion. The following line
gives me error 3159; not a valid bookmark. The "Me." in that line wouldn't
still refer to the calling form, right? It is within that "With..End With"
loop...

If Not .NoMatch Then Me.Bookmark = .Bookmark


Thanks!
Fred


Marshall Barton said:
Fred said:
I have two related forms: Frm_LibraryDataEdit and Frm_LibraryDataFilter. The
first displays book information for editing. The second displays book
information for searching. There is a command button on each form which will
open the related form, and position the related form to the same record as
the calling form. This works fine, using OpenArgs, if the form being called
is not already open.

However, if the form being called *is* already open, I can't seem to
synchronize it to the calling form. I include the code below. I have
confirmed that the IsLoaded( ) function is returning the proper value, and
the the correct Book_ID is available to the FindFirst command.



1. If I am calling a form which is already open, is "DoCmd.OpenForm" the
appropriate command?

That will give the focus to the form.

2. What is wrong with my code? :(

(Isloaded( ) is the standard function from Northwind Traders.)

If ISLOADED("Frm_LibraryDataFilter") Then

DoCmd.OpenForm ("Frm_LibraryDataFilter")
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Book_ID] = " & _
Forms!Frm_LibraryDataEdit!txtBook_ID
Me.Bookmark = rs.Bookmark
Else

I think you have the Form objects mixed up here. Me refers
to the calling form, but you want to find the corresponding
record in the called form:

DoCmd.OpenForm ("Frm_LibraryDataFilter")
With Forms("Frm_LibraryDataFilter").RecordsetClone
.FindFirst "[Book_ID] = " & Me.txtBook_ID
If Not .NoMatch Then Me.Bookmark = .Bookmark
End With
Else
 
Hello again, Marsh:

I've been experimenting with code and the following *does* seem to work:

DoCmd.OpenForm ("Frm_LibraryDataFilter")

With Forms("Frm_LibraryDataFilter").RecordsetClone
.FindFirst "[Book_ID] = " & Me.txtBook_ID
If Not .NoMatch Then Forms("Frm_LibraryDataFilter").Bookmark =
..Bookmark
End With

I am not really clear about the ".Bookmark" in the 4th line of code. That
would be the bookmark of the recordsetclone of "Frm_Library DataFilter", is
that right?


Fred


Marshall Barton said:
Fred said:
I have two related forms: Frm_LibraryDataEdit and Frm_LibraryDataFilter. The
first displays book information for editing. The second displays book
information for searching. There is a command button on each form which will
open the related form, and position the related form to the same record as
the calling form. This works fine, using OpenArgs, if the form being called
is not already open.

However, if the form being called *is* already open, I can't seem to
synchronize it to the calling form. I include the code below. I have
confirmed that the IsLoaded( ) function is returning the proper value, and
the the correct Book_ID is available to the FindFirst command.



1. If I am calling a form which is already open, is "DoCmd.OpenForm" the
appropriate command?

That will give the focus to the form.

2. What is wrong with my code? :(

(Isloaded( ) is the standard function from Northwind Traders.)

If ISLOADED("Frm_LibraryDataFilter") Then

DoCmd.OpenForm ("Frm_LibraryDataFilter")
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Book_ID] = " & _
Forms!Frm_LibraryDataEdit!txtBook_ID
Me.Bookmark = rs.Bookmark
Else

I think you have the Form objects mixed up here. Me refers
to the calling form, but you want to find the corresponding
record in the called form:

DoCmd.OpenForm ("Frm_LibraryDataFilter")
With Forms("Frm_LibraryDataFilter").RecordsetClone
.FindFirst "[Book_ID] = " & Me.txtBook_ID
If Not .NoMatch Then Me.Bookmark = .Bookmark
End With
Else
 
Fred said:
I've been experimenting with code and the following *does* seem to work:

DoCmd.OpenForm ("Frm_LibraryDataFilter")

With Forms("Frm_LibraryDataFilter").RecordsetClone
.FindFirst "[Book_ID] = " & Me.txtBook_ID
If Not .NoMatch Then Forms("Frm_LibraryDataFilter").Bookmark =
.Bookmark
End With

I am not really clear about the ".Bookmark" in the 4th line of code. That
would be the bookmark of the recordsetclone of "Frm_Library DataFilter", is
that right?

Sorry, Fred, I made the same mistake you did at the same
time I'm telling you what you did wrong. Now you've got it
the way I intended it to be.

You also have the right idea about the .Bookmark. Since
there is no object specified, it's a property of the object
specified in the With statement.
 
Sorry, Fred, I made the same mistake you did at the same
time I'm telling you what you did wrong. Now you've got it
the way I intended it to be.

Hey, Marsh! I'm not buying that for a minute! You put that mistake in on
purpose to see if I was paying attention, didn't you! ;)

Thanks so much!

Fred
 
Fred said:
Hey, Marsh! I'm not buying that for a minute! You put that mistake in on
purpose to see if I was paying attention, didn't you! ;)


Aw shucks, Fred, I ain't that clever ;-)

Whatever! It's great that you figured it all out
in spite my efforts to confuse the issue, kind of
lessens my embarrassment a little ;-)
 
Back
Top