Position to Added Record when in Focus

  • Thread starter Thread starter Dave F
  • Start date Start date
D

Dave F

I have a record inquiry form (Form A) that users can use to view records in
a table/query. This form (Form A) has a button that opens a form (Form B)
that allows the user add a new record to the table. This form (Form B) has
a button to Add or Cancel the entry and return focus to Form A.

When I return focus to Form A, how can I get it to position (or display) the
record I just added to the table?

Thanks,
Dave F
 
Dave F said:
I have a record inquiry form (Form A) that users can use to view
records in a table/query. This form (Form A) has a button that opens
a form (Form B) that allows the user add a new record to the table.
This form (Form B) has a button to Add or Cancel the entry and return
focus to Form A.

When I return focus to Form A, how can I get it to position (or
display) the record I just added to the table?

You have to do two things: requery form A to get the added record into
its recordset, and then position form A to that record. To locate the
record, the record must have a unique key, which will be known to form
B. Suppose that field is named "ID" and is a numeric field. Then you
could have code behind form B's Add button along these lines:

Dim lngID As Long

' Save the ID of the new record.
lngID = Me!ID

' ... Save the record, by whatever mechanism is appropriate.

' Then ...

With Forms!FormA
.Requery
.Recordset .Findfirst "ID=" & lngID
End With
 
Where do I put the:

With Forms!FormA
.Requery
.Recordset .Findfirst "ID=" & lngID
End With

Do I put this in Form A On Got Focus event ? or do I put it some where else?

Thanks,
Dave F.
 
Dave F said:
Where do I put the:

With Forms!FormA
.Requery
.Recordset .Findfirst "ID=" & lngID
End With

Do I put this in Form A On Got Focus event ? or do I put it some
where else?

Thanks,
Dave F.

As I said above, it would go in with the existing code for the Add
button on form B. In other words, the code for that button's Click
event procedure takes these steps:

1) saves the ID value of the record that will be added,

2) saves that record in the table, and

3) uses code modelled on the "With Forms!FormA ... End With" block
to requery and reposition form A.

This all happens in the Add button's Click event on form B.

*Typo Alert* I accidentally inserted an invalid space in one of the
example lines I gave you. This line:

should be

.Recordset.Findfirst "ID=" & lngID

Note that there is no space between ".Recordset" and ".FindFirst" in the
corrected line.
 
Back
Top