Moving a value from one form to another

G

gmfbard

Hello,

My application requires that data entry people check to see if a
contact already exists in the database before entering a new "contact
log" incident.

I have created six search forms, each based on a separate parameter
query. For example, the data entry person can begin by searching on
"town" to see if there are any existing contacts from a particular
town.

The search form works well. It displays every contact living in a town
that corresponds to what the data entry person keystroked into the
parameter dialog box.

The next step is for the data entry person to select a contact by
clicking on the contact's ID, and then to click on my "Open Contact
Log" command button.

The following code, attached to the button's "On Click" event opens
the proper form and displays a record wherein the contact ID matches
the one found in the search form:


Code:
Private Sub cmdOpenContactLog_Click()
On Error GoTo Err_cmdOpenContactLog_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmContactServicesLog"

stLinkCriteria = "[VictimID]=" & Me![VictimID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Me![VictimID].SetFocus

DoCmd.Close acForm, Me.Name

Exit_cmdOpenContactLog_Click:
Exit Sub

Err_cmdOpenContactLog_Click:
MsgBox Err.Description
Resume Exit_cmdOpenContactLog_Click

End Sub

However, I need for the Contact form to open in a New Record, and to
do so with the contact ID already populated with the contact ID
selected in the search form.

When I add a "DoCmd.GoToRecord, , acNewRecord" line, the Contact form
opens in a new record, but the contact ID field is blank.

How can I get the form to open in a new record and have the contact ID
field match the contact ID field selected in the search form?

Thanks for all your help.

George M.
 
D

Dirk Goldgar

gmfbard said:
Hello,

My application requires that data entry people check to see if a
contact already exists in the database before entering a new "contact
log" incident.

I have created six search forms, each based on a separate parameter
query. For example, the data entry person can begin by searching on
"town" to see if there are any existing contacts from a particular
town.

The search form works well. It displays every contact living in a town
that corresponds to what the data entry person keystroked into the
parameter dialog box.

The next step is for the data entry person to select a contact by
clicking on the contact's ID, and then to click on my "Open Contact
Log" command button.

The following code, attached to the button's "On Click" event opens
the proper form and displays a record wherein the contact ID matches
the one found in the search form:


Code:
Private Sub cmdOpenContactLog_Click()
On Error GoTo Err_cmdOpenContactLog_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmContactServicesLog"

stLinkCriteria = "[VictimID]=" & Me![VictimID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Me![VictimID].SetFocus

DoCmd.Close acForm, Me.Name

Exit_cmdOpenContactLog_Click:
Exit Sub

Err_cmdOpenContactLog_Click:
MsgBox Err.Description
Resume Exit_cmdOpenContactLog_Click

End Sub

However, I need for the Contact form to open in a New Record, and to
do so with the contact ID already populated with the contact ID
selected in the search form.

When I add a "DoCmd.GoToRecord, , acNewRecord" line, the Contact form
opens in a new record, but the contact ID field is blank.

How can I get the form to open in a new record and have the contact ID
field match the contact ID field selected in the search form?

Thanks for all your help.


Try this:

DoCmd.OpenForm stDocName, , , stLinkCriteria
With Forms(strDocName)
.Recordset.AddNew
!VictimID.DefaultValue = Me!VictimID
End With


That assumes that the linking control on both forms is named "VictimID".
 
G

gmfbard

My application requires that data entry people check to see if a
contact already exists in the database before entering a new "contact
log" incident.
I have created six search forms, each based on a separate parameter
query. For example, the data entry person can begin by searching on
"town" to see if there are any existing contacts from a particular
town.
The search form works well. It displays every contact living in a town
that corresponds to what the data entry person keystroked into the
parameter dialog box.
The next step is for the data entry person to select a contact by
clicking on the contact's ID, and then to click on my "Open Contact
Log" command button.
The following code, attached to the button's "On Click" event opens
the proper form and displays a record wherein the contact ID matches
the one found in the search form:
Code:
Private Sub cmdOpenContactLog_Click()
On Error GoTo Err_cmdOpenContactLog_Click[/QUOTE]
[QUOTE]
Dim stDocName As String
Dim stLinkCriteria As String[/QUOTE]
[QUOTE]
stDocName = "frmContactServicesLog"[/QUOTE]
[QUOTE]
stLinkCriteria = "[VictimID]=" & Me![VictimID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Me![VictimID].SetFocus[/QUOTE]
[QUOTE]
DoCmd.Close acForm, Me.Name[/QUOTE]
[QUOTE]
Exit_cmdOpenContactLog_Click:
Exit Sub[/QUOTE]
[QUOTE]
Err_cmdOpenContactLog_Click:
MsgBox Err.Description
Resume Exit_cmdOpenContactLog_Click[/QUOTE]
[QUOTE]
End Sub
However, I need for the Contact form to open in a New Record, and to
do so with the contact ID already populated with the contact ID
selected in the search form.
When I add a "DoCmd.GoToRecord, , acNewRecord" line, the Contact form
opens in a new record, but the contact ID field is blank.
How can I get the form to open in a new record and have the contact ID
field match the contact ID field selected in the search form?
Thanks for all your help.

Try this:

DoCmd.OpenForm stDocName, , , stLinkCriteria
With Forms(strDocName)
.Recordset.AddNew
!VictimID.DefaultValue = Me!VictimID
End With

That assumes that the linking control on both forms is named "VictimID".

Hello Dirk,

This is awesome! It does precisely what I need. Thank you so much.

George M.
 

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