Bookmark, part 2

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Thanks to PC Datasheet for prior help; another issue arises beyond my
ability. I guess I don't understand this bookmark thing enough to adapt.

I am creating a new client: from my [MainClientForm] a command button opens
a form to generate a NotInList routine and assign a new ClientID, then opens
an entry form passing the ClientID via OpenArgs. OK--so now the entry form
is complete with details including the newly assigned ClientID.

I close the entry form to return to [MainClientForm].
My new client is available in the combo box selector thanks to a requery of
the cbo, but the [MainClientForm] is returned (via requery) to the first
record. No surprise, but I want it at the newly created client.

Bookmark, I know. Cannot do it though. I cannot seem to logic it through or
be lucky enough to back into it. HELP?
 
Chris said:
I am creating a new client: from my [MainClientForm] a command button opens
a form to generate a NotInList routine and assign a new ClientID, then opens
an entry form passing the ClientID via OpenArgs. OK--so now the entry form
is complete with details including the newly assigned ClientID.

I close the entry form to return to [MainClientForm].
My new client is available in the combo box selector thanks to a requery of
the cbo, but the [MainClientForm] is returned (via requery) to the first
record. No surprise, but I want it at the newly created client.

Bookmark, I know. Cannot do it though. I cannot seem to logic it through or
be lucky enough to back into it. HELP?


Save the main form current record's primary key field's
value before the requery. After the requery, search for
that key and move the form to that record:

Dim varKey As Long
varKey = Me.keyfield
Me.Requery
With Me.RecordsetClone
.FindFirst "keyfield = " & varKey
If Not .NoMatch Then Me.Bookmark = .Bookmark
End With
 
Marsh, thanks for the response. Still having trouble. Disclaimer: I am very
much an amateur.

I adjusted your code as my ClientID field is text. I THINK I did it
correctly.

I close the client entry form properly, it exists in my main form's combo
box and I can select it for display, but upon closing the client entry form
the main form still displays the first record -- not the newly created one.

The code I tried is:
Dim strClientID As String
strClientID = Me.ClientID
With Me.RecordsetClone
.FindFirst "ClientID=""" & strClientID & """"
If Not .NoMatch Then Me.Bookmark = .Bookmark
End With

I verified there is no requery affecting the main form during close of the
entry form or focus, activate, etc. of the main form. The code above resides
just ahead of the final End If of the closing routine.

Did I do it correctly?
--
Thanks for your help,
Chris


Marshall Barton said:
Chris said:
I am creating a new client: from my [MainClientForm] a command button opens
a form to generate a NotInList routine and assign a new ClientID, then opens
an entry form passing the ClientID via OpenArgs. OK--so now the entry form
is complete with details including the newly assigned ClientID.

I close the entry form to return to [MainClientForm].
My new client is available in the combo box selector thanks to a requery of
the cbo, but the [MainClientForm] is returned (via requery) to the first
record. No surprise, but I want it at the newly created client.

Bookmark, I know. Cannot do it though. I cannot seem to logic it through or
be lucky enough to back into it. HELP?


Save the main form current record's primary key field's
value before the requery. After the requery, search for
that key and move the form to that record:

Dim varKey As Long
varKey = Me.keyfield
Me.Requery
With Me.RecordsetClone
.FindFirst "keyfield = " & varKey
If Not .NoMatch Then Me.Bookmark = .Bookmark
End With
 
Chris said:
Marsh, thanks for the response. Still having trouble. Disclaimer: I am very
much an amateur.

I adjusted your code as my ClientID field is text. I THINK I did it
correctly.

I close the client entry form properly, it exists in my main form's combo
box and I can select it for display, but upon closing the client entry form
the main form still displays the first record -- not the newly created one.

The code I tried is:
Dim strClientID As String
strClientID = Me.ClientID
With Me.RecordsetClone
.FindFirst "ClientID=""" & strClientID & """"
If Not .NoMatch Then Me.Bookmark = .Bookmark
End With

I verified there is no requery affecting the main form during close of the
entry form or focus, activate, etc. of the main form. The code above resides
just ahead of the final End If of the closing routine.

Did I do it correctly?


Well, the code looks valid, but you took out the marker line
(requery) I had in there to indicate that the code had to be
executed in two stages. Saving the key field before
whatever causes the main form to reposition from the
desired record back to the first record. The part after the
requery is only useful if executed after whatever causes the
mainform's current record to change. The way you have put
the two parts together, it will not do anything useful.
Sorry if I didn't make that distinction clear.

It almost sounds like you might have placed that code in the
client entry form, I had intended it to be in the main form,
probably in the button's click event procedure (with the
OpenForm replacing my requery line).

In order to make the main form return to the record that was
current before all this stuff happens, we will have to
determine the reason for the main form changing its current
record.

There may be some confusion here. Somewhere you need to
have a combobox.Requery statement to makethe newly entered
client show up in the como box. Is it possible that you
have form.Requery instead?
 
Thanks again.
client entry form, ..."

Yes, it is at present. Reminder: I actually am using three forms.

[MainForm] main client form, ALL client data available via here (buttons,
etc.)

[ClientEntry] used to enter BASIC client details; setup account only.

[ClientSetup] validates new ClientID, uses NotInList to generate the new
code and then opens up [ClientEntry] with that new code (via NewArgs).

At the close of [ClientEntry] I do requery the combo on [MainForm] so the
new client's account code is available for selection. That works.
current before all this stuff happens, we will have to
determine the reason for the main form changing its current
record."

Oops! It does return to the previously viewed record. But I am wanting to
go to the record just created. Sorry for that confusion.

Does that help?
 
Chris said:
client entry form, ..."

Yes, it is at present. Reminder: I actually am using three forms.

[MainForm] main client form, ALL client data available via here (buttons,
etc.)

[ClientEntry] used to enter BASIC client details; setup account only.

[ClientSetup] validates new ClientID, uses NotInList to generate the new
code and then opens up [ClientEntry] with that new code (via NewArgs).

At the close of [ClientEntry] I do requery the combo on [MainForm] so the
new client's account code is available for selection. That works.
current before all this stuff happens, we will have to
determine the reason for the main form changing its current
record."

Oops! It does return to the previously viewed record. But I am wanting to
go to the record just created. Sorry for that confusion.


So, you want the main form to navigate to the record that
the other form just created. This record will be the one
indentified by the value of the combo box. In this case,
all my concerns about the main form being at its first
record are irrelevant. Try using this slight adjustment to
the procedure.

With Me.RecordsetClone
.FindFirst "ClientID=""" & Me.thecombo & """"
If Not .NoMatch Then Me.Bookmark = .Bookmark
End With

Note that using Me in the above implies that the code is in
the main form's module.
 
I tried. Error, method or data member not found -- on the
"Me.cboSelectClient".

I'm lost, truly. Earlier I said it wasn't reverting to first record, but
then the main form's requery has to be used in order to select the new record
(otherwise it just appears in the combo box (because of its requery) and does
not retrieve. Thus it does revert to record one. My bad, sorry.

Here is navigation and code presently in the close routine of the Entry Form
that produces the above error.

form [frm1VE Client] is the main form.
form [frm1DE Client] is the entry form.
form [frm1DE ClientSetup] is the NotInList, open args form.

Navigation:

button on [frm1VE Client] at any client opens [frm1DE ClientSetup].

combo box on [frm1DE ClientSetup] (NotInList and open args) uses OnUpdate
event to open [frm1DE Client] to enter data for new client.

closing routine (button) on [frm1DE Client] updates combo box on [frm1VE
Client] for NEW client, requeries [frm1VE Client] to assure retrieval of New
client.

Record up is the first record. Needs to be NEW client.

Code:
Forms![frm1VE Client].Form![cboSelectClient].Requery
Forms![frm1VE Client].Requery

With Me.RecordsetClone
.FindFirst "ClientID=""" & Me.cboSelectClient & """"
If Not .NoMatch Then Me.Bookmark = .Bookmark
End With


I must really be missing something. I have to believe that I can be viewing
client one, go to an entry form to create client two, and upon closing that
entry form go back to view the newly created client's record.

I do appreciate your helping, really.

--
Thanks for your help,
Chris


Marshall Barton said:
Chris said:
"It almost sounds like you might have placed that code in the
client entry form, ..."

Yes, it is at present. Reminder: I actually am using three forms.

[MainForm] main client form, ALL client data available via here (buttons,
etc.)

[ClientEntry] used to enter BASIC client details; setup account only.

[ClientSetup] validates new ClientID, uses NotInList to generate the new
code and then opens up [ClientEntry] with that new code (via NewArgs).

At the close of [ClientEntry] I do requery the combo on [MainForm] so the
new client's account code is available for selection. That works.
"In order to make the main form return to the record that was
current before all this stuff happens, we will have to
determine the reason for the main form changing its current
record."

Oops! It does return to the previously viewed record. But I am wanting to
go to the record just created. Sorry for that confusion.


So, you want the main form to navigate to the record that
the other form just created. This record will be the one
indentified by the value of the combo box. In this case,
all my concerns about the main form being at its first
record are irrelevant. Try using this slight adjustment to
the procedure.

With Me.RecordsetClone
.FindFirst "ClientID=""" & Me.thecombo & """"
If Not .NoMatch Then Me.Bookmark = .Bookmark
End With

Note that using Me in the above implies that the code is in
the main form's module.
 
Chris said:
I tried. Error, method or data member not found -- on the
"Me.cboSelectClient".

I'm lost, truly. Earlier I said it wasn't reverting to first record, but
then the main form's requery has to be used in order to select the new record
(otherwise it just appears in the combo box (because of its requery) and does
not retrieve. Thus it does revert to record one. My bad, sorry.

Here is navigation and code presently in the close routine of the Entry Form
that produces the above error.

form [frm1VE Client] is the main form.
form [frm1DE Client] is the entry form.
form [frm1DE ClientSetup] is the NotInList, open args form.

Navigation:

button on [frm1VE Client] at any client opens [frm1DE ClientSetup].

combo box on [frm1DE ClientSetup] (NotInList and open args) uses OnUpdate
event to open [frm1DE Client] to enter data for new client.

closing routine (button) on [frm1DE Client] updates combo box on [frm1VE
Client] for NEW client, requeries [frm1VE Client] to assure retrieval of New
client.

Record up is the first record. Needs to be NEW client.

Code:
Forms![frm1VE Client].Form![cboSelectClient].Requery
Forms![frm1VE Client].Requery

With Me.RecordsetClone
.FindFirst "ClientID=""" & Me.cboSelectClient & """"
If Not .NoMatch Then Me.Bookmark = .Bookmark
End With


I must really be missing something. I have to believe that I can be viewing
client one, go to an entry form to create client two, and upon closing that
entry form go back to view the newly created client's record.


Ok, that really helps. I had assumed the code was in form
[frm1VE Client]. If the code is in a different form, you
can't use Me to refer to [frm1VE Client]. Let's modify it
to work in the other form:

Dim frm As Form
Set frm = Forms![frm1VE Client]
frm.[cboSelectClient].Requery
frm.Requery

With frm.RecordsetClone
.FindFirst "ClientID=""" & frm.cboSelectClient & """"
If Not .NoMatch Then frm.Bookmark = .Bookmark
End With
Set frm = Nothing
 
Thanks, once again.

Small success! Returns to previously viewed record, but not the NEW record
yet.

Using code:
Dim frm As Form
Set frm = Forms![frm1VE Client]
frm.[cboSelectClient].Requery
frm.Requery

With frm.RecordsetClone
.FindFirst "ClientID=""" & frm.cboSelectClient & """"
If Not .NoMatch Then frm.Bookmark = .Bookmark
End With
Set frm = Nothing

DoCmd.Close acForm, "frm1DE Client", acSaveYes

I'm sure that now its something obvious. I wish I could see it.

--
Thanks for your help,
Chris


Marshall Barton said:
Chris said:
I tried. Error, method or data member not found -- on the
"Me.cboSelectClient".

I'm lost, truly. Earlier I said it wasn't reverting to first record, but
then the main form's requery has to be used in order to select the new record
(otherwise it just appears in the combo box (because of its requery) and does
not retrieve. Thus it does revert to record one. My bad, sorry.

Here is navigation and code presently in the close routine of the Entry Form
that produces the above error.

form [frm1VE Client] is the main form.
form [frm1DE Client] is the entry form.
form [frm1DE ClientSetup] is the NotInList, open args form.

Navigation:

button on [frm1VE Client] at any client opens [frm1DE ClientSetup].

combo box on [frm1DE ClientSetup] (NotInList and open args) uses OnUpdate
event to open [frm1DE Client] to enter data for new client.

closing routine (button) on [frm1DE Client] updates combo box on [frm1VE
Client] for NEW client, requeries [frm1VE Client] to assure retrieval of New
client.

Record up is the first record. Needs to be NEW client.

Code:
Forms![frm1VE Client].Form![cboSelectClient].Requery
Forms![frm1VE Client].Requery

With Me.RecordsetClone
.FindFirst "ClientID=""" & Me.cboSelectClient & """"
If Not .NoMatch Then Me.Bookmark = .Bookmark
End With


I must really be missing something. I have to believe that I can be viewing
client one, go to an entry form to create client two, and upon closing that
entry form go back to view the newly created client's record.


Ok, that really helps. I had assumed the code was in form
[frm1VE Client]. If the code is in a different form, you
can't use Me to refer to [frm1VE Client]. Let's modify it
to work in the other form:

Dim frm As Form
Set frm = Forms![frm1VE Client]
frm.[cboSelectClient].Requery
frm.Requery

With frm.RecordsetClone
.FindFirst "ClientID=""" & frm.cboSelectClient & """"
If Not .NoMatch Then frm.Bookmark = .Bookmark
End With
Set frm = Nothing
 
Chris said:
Small success! Returns to previously viewed record, but not the NEW record
yet.

Using code:
Dim frm As Form
Set frm = Forms![frm1VE Client]
frm.[cboSelectClient].Requery
frm.Requery

With frm.RecordsetClone
.FindFirst "ClientID=""" & frm.cboSelectClient & """"
If Not .NoMatch Then frm.Bookmark = .Bookmark
End With
Set frm = Nothing

DoCmd.Close acForm, "frm1DE Client", acSaveYes

I'm sure that now its something obvious. I wish I could see it.


Can you verify that the combo box selection agrees with the
record that you want to select and that the record you want
to be the current record is actually part of the form's
dataset?

I think going to the wrong record means that the value in
the combo box is not identifying the new entry. Either
there's still a misunderstanding or maybe it's a timing
issue.

If it is a timing issue, then we need to use the ClientID of
the record that was added (instead of the combo box value).
Can you make the ClientID that was assigned to the new
record available to our procedure???

On a separate issue, you do **not** want to use acSaveYes
when you close the form. That tells Access to save the
form's design, which you should almost never do in a running
program.
 
Success! I made the following change per your suggestion:

..FindFirst "ClientID=""" & Me.ClientID & """"

Marsh, I really appreciate your help and patience. You MVP are great!
 
Chris said:
Success! I made the following change per your suggestion:

.FindFirst "ClientID=""" & Me.ClientID & """"

Marsh, I really appreciate your help and patience. You MVP are great!


That is good to hear. Thanks for closing out the thread.
 
Back
Top