setting data between form

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

Guest

hi,

I has two forms open. One form show all the data in datasheet view. How do
we transfer the record from the form (with datasheet view) to another form

ie the user select a records from a table and dispay it in a form format.

many thanks
 
Hi there

One way you could do this is to simply create the second form to show a
single record from the same data as the datasheet. Then set it up so that
when you double click a record in the datasheet, it opens the second form up
showing the correct record. This is quite easy.

You will need to make sure that the Primary Key field is in the datasheet.
(You might be able to turn it invisible if you want though, experiment with
this.) The Primary Key field must also be in the record source for the second
form.

First you need to put some code in the datasheet's On Click event. Select
one of the controls in the datasheet, and bring up its Properties. Click the
Event tab. Select the On Double Click event. Click the little button with the
three dots. Choose 'Code Builder'. Insert the following code between Sub and
End Sub:

DoCmd.Close acform, "Name of second form"
DoCmd.Openform "Name of second form", , , "[Primary Key field] = " &
[Forms]![Name of datasheet form]![Name of control containing Primary Key
field]

Obviously you will need to change all form names, field names etc to the
actual ones in your database.

Repeat this code for the On Double Click events for the other controls on
the datasheet form. Once you have done this, if you double click on any
record in the datasheet, the second form will open up showing the record you
double clicked in the datasheet.

Hope this helps.

David
 
Back
Top