Using a Button to take an autonumbr from one form to populate anot

G

Guest

Using a Button to take an autonumbr from one form to populate another
autonumber field on another field.

I have a Mainform "A" with a button and code that opens another Mainform "B"
with a subform which has the same table as Mainform "A".

The button is supposed to tell the subform with the autonumber field that
whatever appears there should be the same number In Mainform A.

How do I add code to my button, that opens Mainform B, and reach down and
link to the its subform with the same populated autonumber field ?

This is the Open Form button code that I am using:

Private Sub Command116_Click()
On Error GoTo err_Command116_click
Dim stDocName As String
Dim stLinkCriteria As String
DoCmd.RunCommand acCmdSaveRecord

stDocName = "frmMain"
stLinkCriteria = "[txtGuestID]=" & Me![GuestID] 'BOTH ARE AUTONUMBER FIELDS
DoCmd.OpenForm stDocName, , , stLinkCriteria
exit_Command116_click:
Exit Sub
err_Command116_click:
'MsgBox "Type/Select a 'Entry's Name', before clicking on 'Registration'."
Resume exit_Command116_click
End Sub

John
 
G

Guest

Does the Form B bound to a table that contain a field named txtGuestID, or
txtGuestID is an unbound field on the mainform B?

If Form B open from Form A only, then you can link the sub form to MainForm
A, using the recordsource of the SubForm in Form B
Select * From TableName Where [GuestID field name] = Forms![Main Form
A]![GuestID Field Name in FormA]
============================================
If FormB bounded to a table that contain a field called txtGuestID, you can
link the formB and the subform using the parent child link
Parent = txtGuestID
child = GuestID
============================================
if form B, is not bound to a table, and the field txtGuestID is an unbound
field, then there is no point sending criteria with the open form command,
instead you can pass the GuestID field value, using the openArgs in the
command line.

And then you can use the OpenArgs as the filter for the sub form,
On the on load event of the FormB write the code

Me.[SubFormControlName].Form.controlSource = "Select * From Tablename Where
GuestID = " & Me.OpenArgs
 
G

Guest

Form B is an "unbound" form; it is the subform that is bound and has the
autonumber field that must be populated with the same autonumber record from
Form A's autonumber.

The code below, "stLinkCriteria = "[txtGuestID]=" & Me![GuestID]" contains
two bound autonumber fields. However, "txtGuestId" is on unbound FormB's
first bound subform.

John

Ofer said:
Does the Form B bound to a table that contain a field named txtGuestID, or
txtGuestID is an unbound field on the mainform B?

If Form B open from Form A only, then you can link the sub form to MainForm
A, using the recordsource of the SubForm in Form B
Select * From TableName Where [GuestID field name] = Forms![Main Form
A]![GuestID Field Name in FormA]
============================================
If FormB bounded to a table that contain a field called txtGuestID, you can
link the formB and the subform using the parent child link
Parent = txtGuestID
child = GuestID
============================================
if form B, is not bound to a table, and the field txtGuestID is an unbound
field, then there is no point sending criteria with the open form command,
instead you can pass the GuestID field value, using the openArgs in the
command line.

And then you can use the OpenArgs as the filter for the sub form,
On the on load event of the FormB write the code

Me.[SubFormControlName].Form.controlSource = "Select * From Tablename Where
GuestID = " & Me.OpenArgs

--
I hope that helped
Good luck


John Phelan said:
Using a Button to take an autonumbr from one form to populate another
autonumber field on another field.

I have a Mainform "A" with a button and code that opens another Mainform "B"
with a subform which has the same table as Mainform "A".

The button is supposed to tell the subform with the autonumber field that
whatever appears there should be the same number In Mainform A.

How do I add code to my button, that opens Mainform B, and reach down and
link to the its subform with the same populated autonumber field ?

This is the Open Form button code that I am using:

Private Sub Command116_Click()
On Error GoTo err_Command116_click
Dim stDocName As String
Dim stLinkCriteria As String
DoCmd.RunCommand acCmdSaveRecord

stDocName = "frmMain"
stLinkCriteria = "[txtGuestID]=" & Me![GuestID] 'BOTH ARE AUTONUMBER FIELDS
DoCmd.OpenForm stDocName, , , stLinkCriteria
exit_Command116_click:
Exit Sub
err_Command116_click:
'MsgBox "Type/Select a 'Entry's Name', before clicking on 'Registration'."
Resume exit_Command116_click
End Sub

John
 
G

Guest

In that case there is no point in sending the criteria, use the OpenArgs to
pass a parameter to the second form
DoCmd.OpenForm stDocName,,,,,,Me![GuestID]

On the On Load event of the form, write the code
Me.[SubFormControlName].Form.controlSource = "Select * From Tablename Where
[GuestID] = " & Me.OpenArgs

--
I hope that helped
Good luck


John Phelan said:
Form B is an "unbound" form; it is the subform that is bound and has the
autonumber field that must be populated with the same autonumber record from
Form A's autonumber.

The code below, "stLinkCriteria = "[txtGuestID]=" & Me![GuestID]" contains
two bound autonumber fields. However, "txtGuestId" is on unbound FormB's
first bound subform.

John

Ofer said:
Does the Form B bound to a table that contain a field named txtGuestID, or
txtGuestID is an unbound field on the mainform B?

If Form B open from Form A only, then you can link the sub form to MainForm
A, using the recordsource of the SubForm in Form B
Select * From TableName Where [GuestID field name] = Forms![Main Form
A]![GuestID Field Name in FormA]
============================================
If FormB bounded to a table that contain a field called txtGuestID, you can
link the formB and the subform using the parent child link
Parent = txtGuestID
child = GuestID
============================================
if form B, is not bound to a table, and the field txtGuestID is an unbound
field, then there is no point sending criteria with the open form command,
instead you can pass the GuestID field value, using the openArgs in the
command line.

And then you can use the OpenArgs as the filter for the sub form,
On the on load event of the FormB write the code

Me.[SubFormControlName].Form.controlSource = "Select * From Tablename Where
GuestID = " & Me.OpenArgs

--
I hope that helped
Good luck


John Phelan said:
Using a Button to take an autonumbr from one form to populate another
autonumber field on another field.

I have a Mainform "A" with a button and code that opens another Mainform "B"
with a subform which has the same table as Mainform "A".

The button is supposed to tell the subform with the autonumber field that
whatever appears there should be the same number In Mainform A.

How do I add code to my button, that opens Mainform B, and reach down and
link to the its subform with the same populated autonumber field ?

This is the Open Form button code that I am using:

Private Sub Command116_Click()
On Error GoTo err_Command116_click
Dim stDocName As String
Dim stLinkCriteria As String
DoCmd.RunCommand acCmdSaveRecord

stDocName = "frmMain"
stLinkCriteria = "[txtGuestID]=" & Me![GuestID] 'BOTH ARE AUTONUMBER FIELDS
DoCmd.OpenForm stDocName, , , stLinkCriteria
exit_Command116_click:
Exit Sub
err_Command116_click:
'MsgBox "Type/Select a 'Entry's Name', before clicking on 'Registration'."
Resume exit_Command116_click
End Sub

John
 

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