Go to Current Record on load

S

Scuda

Hi All, hope everyone here in the states had a nice thanksgiving.

I have a form where I fill in information pertaining to that case (record).
There are certain types of cases that require an additional form be filled
out. What I did was create a command button to the new form and on that new
form I had a command button that when clicked, filled in the form with the
information from the Last Record in the table. I removed that button and put
it in the On Open section of my new form:

Private Sub Form_Open(Cancel As Integer)

DoCmd.GoToRecord , , acLast
End Sub

Which worked fine, but I need it to go the CURRENT record, not the last one.
For some reason this did not work:
Private Sub Form_Open(Cancel As Integer)

DoCmd.GoToRecord , , acCurrent
End Sub

Someone tell me what I am doing wrong?

Thanks!
 
R

Rick Brandt

Scuda said:
Hi All, hope everyone here in the states had a nice thanksgiving.

I have a form where I fill in information pertaining to that case (record).
There are certain types of cases that require an additional form be filled
out. What I did was create a command button to the new form and on that new
form I had a command button that when clicked, filled in the form with the
information from the Last Record in the table. I removed that button and put
it in the On Open section of my new form:

Private Sub Form_Open(Cancel As Integer)

DoCmd.GoToRecord , , acLast
End Sub

Which worked fine, but I need it to go the CURRENT record, not the last one.
For some reason this did not work:
Private Sub Form_Open(Cancel As Integer)

DoCmd.GoToRecord , , acCurrent
End Sub

Someone tell me what I am doing wrong?

Your question makes no sense. By definition the current record is the record
you are currently on. There is never a need to go to the current record because
you are already there.

Did you mean that you want the second form to be positioned to a record that is
related to the record in the first form? The Command button wizard will create
a button that does that for you.

Are these two forms bound to the same table or different tables?
 
S

Scuda

Hi Rick, yes they are bound to the same table. And my question was a little
messy.

When I went to the second form it always reverted back to the First Record
in the table, so thats when I created the Command button to go to the last. I
was just curious if I could do that automatically when the second form is
launched.

Thanks
 
R

Rick Brandt

Scuda said:
Hi Rick, yes they are bound to the same table. And my question was a little
messy.

When I went to the second form it always reverted back to the First Record
in the table, so thats when I created the Command button to go to the last. I
was just curious if I could do that automatically when the second form is
launched.

As stated, the command button wizard will create a button for you that will open
the second form pre-filtered to the primary key value of the first form.

However; you really should not try to have two forms modifying the same record.
As far as Access is concerned that is the same as two different users modifying
the same record at the same time and you will get a conflict error.

You could have your button code save the first record before opening the second
form and that might avoid the conflict error, but it would be easier to just
place the additional fields that you currently have on a separate form on the
same form using a TabControl.

Just place all your current form1 controls on the first page of the TabControl
and all of your form2 controls onto the second page of the TabControl. No need
to figure out how to go to the correct record with that setup.
 
S

Scuda

Thanks rick, I'll give it a try, good stuff.!

Rick Brandt said:
As stated, the command button wizard will create a button for you that will open
the second form pre-filtered to the primary key value of the first form.

However; you really should not try to have two forms modifying the same record.
As far as Access is concerned that is the same as two different users modifying
the same record at the same time and you will get a conflict error.

You could have your button code save the first record before opening the second
form and that might avoid the conflict error, but it would be easier to just
place the additional fields that you currently have on a separate form on the
same form using a TabControl.

Just place all your current form1 controls on the first page of the TabControl
and all of your form2 controls onto the second page of the TabControl. No need
to figure out how to go to the correct record with that setup.
 

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

Top