Datasheet ?

  • Thread starter Thread starter Mike J
  • Start date Start date
M

Mike J

I have a form that displays one record and I have a button
that opens up another form that displays all the records
in datasheet view. Is it possible to move the pointer to
a record and then close the form, and have the record
chosen displayed in the form that displays one record?
 
Mike J said:
I have a form that displays one record and I have a button
that opens up another form that displays all the records
in datasheet view. Is it possible to move the pointer to
a record and then close the form, and have the record
chosen displayed in the form that displays one record?

Sure. Suppose that your forms are named "frmDetailsView" (showing one
record) and "frmListView" (showing all records in datasheet view), and
the primary key field for both forms is named "ID". Probably the
easiest way to manage it is to have all the form-synchronization code in
the Load and Current events of frmListView. The code module for that
form might look like this:

'------ start of code module for frmListView ------
Option Compare Database
Option Explicit

Private Sub Form_Current()

If CurrentProject.AllForms("frmDetailsView").IsLoaded Then
If Not IsNull(Me!ID) Then
Forms!frmDetailsView.Recordset.FindFirst "ID=" & Me!ID
End If
End If

End Sub

Private Sub Form_Load()

If CurrentProject.AllForms("frmDetailsView").IsLoaded Then
If Not IsNull(Forms!frmDetailsView!ID) Then
Me.Recordset.FindFirst "ID=" & Forms!frmDetailsView!ID
End If
End If

End Sub

'------ end of code module for frmListView ------

Then you'd have a button on frmDetailsView that opens frmListView in
datasheet view, using code like this:

'------ start of code for button on frmDetailsView ------
Private Sub cmdShowList_Click()

DoCmd.OpenForm "frmListView", acFormDS

End Sub
'------ end of code for button on frmDetailsView ------

While both forms are open, frmDetailsView will track the current record
on frmListView (but not vice versa, as I've written this).
 
Back
Top