Vba – MS Access – open a form taking a field value from a previous form


I have a form in an MS Access database which lists all the landowners consulted with for a new electricity line. At the end of each row is a button which opens another form, showing the details of all consultation, offers made etc.

I am trying to use vb in MS Access to take the contactID and automatically put it in a field in the details form, so that landowner's consultation details will pop up automatically. I am not a vb programmer at all (I have a comp sci degree mostly in Java and I'm currently working as a GIS analyst but it's a small company so I've been asked to get an Access database working).

I want to say
[detailsForm]![contactID] = [landownerlist]![ID]
in a way that vb and access will be happy with. Then I can see if I'm on the right track and if it will actually work! What I have above does not actually work. It won't compile.

From Kaliana

Best Solution

If you wish to open a form to a new record and to set the ID there, you can use Openargs, an argument of Openform:

DoCmd.OpenForm "FormName",,,,acFormAdd,,Me.ID

The opened form would also need some code:

If Me.Openargs<>vbNullstring Then
   Me.Id = Me.Openargs
End If

It is also possible to find:

Forms!LandownersList.Recordset.FindFirst "ID=" & Me.ID

or fill in a value:

Forms!LandownersList!Id = Me.ID

on the form being opened from the calling form.

Related Question