Creating sub entry

S

Steve Newport

Sorry basic question but I am going around in circles.

I have a simple supplier table with Supplier ID as key. I open a new table
with a form in preparation to add a new record in the second table
(Contacts). Form opens OK and you can add entries but I want to copy across
the Supplier ID so that it maintains the relationship. Tried several ways but
cant manage it.

The VB behind the relevant button that opens the form reads:

Private Sub CMD_AddContact_Click()
On Error GoTo Err_CMD_AddContact_Click

Dim stDocName As String
Dim stSupplierID As String

stDocName = "FRM_ContactsAdd"
stSupplierID = SupplierID

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal

Exit_CMD_AddContact_Click:
Exit Sub

Err_CMD_AddContact_Click:
MsgBox Err.Description
Resume Exit_CMD_AddContact_Click

End Sub

Which I have messed around with a bit. How should I be doing this?

Many thanks
 
T

Tom van Stiphout

On Thu, 3 Jan 2008 05:39:00 -0800, Steve Newport

You should create a single form, bound to the Suppliers table. Then
have a subform on that form to enter Contacts for the supplier. When
you drop the subform on the form Access will ask you about linking,
and you then link SuppliersID from the parent form to the subform (or
later set the LinkMasterFields and LinkChildFields properties of the
subform control).

Study the Northwind sample application - Orders form: it has an
OrderDetails subform linked to the parent Order.

-Tom.
 
A

Arvin Meyer [MVP]

If you use the last argument, called OpenArgs in the OpenForm Method, you
can get what you want.

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal, Me.[Supplier
ID]

Now, in the second form's Open event use a line like:

Me.txtSupplierID = Me.OpenArgs
 
S

Steve Newport

Many thanks for that - its miore like I expected to do but I am a bit
confused by the second part. The first piece of code I entered using the
DoCmd.Openform was in the event for the button to press to open the second
form.

When you say the second forms Open event - exactly where do you mean? Isn't
it the same block of code?

Arvin Meyer said:
If you use the last argument, called OpenArgs in the OpenForm Method, you
can get what you want.

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal, Me.[Supplier
ID]

Now, in the second form's Open event use a line like:

Me.txtSupplierID = Me.OpenArgs
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Steve Newport said:
Sorry basic question but I am going around in circles.

I have a simple supplier table with Supplier ID as key. I open a new table
with a form in preparation to add a new record in the second table
(Contacts). Form opens OK and you can add entries but I want to copy
across
the Supplier ID so that it maintains the relationship. Tried several ways
but
cant manage it.

The VB behind the relevant button that opens the form reads:

Private Sub CMD_AddContact_Click()
On Error GoTo Err_CMD_AddContact_Click

Dim stDocName As String
Dim stSupplierID As String

stDocName = "FRM_ContactsAdd"
stSupplierID = SupplierID

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal

Exit_CMD_AddContact_Click:
Exit Sub

Err_CMD_AddContact_Click:
MsgBox Err.Description
Resume Exit_CMD_AddContact_Click

End Sub

Which I have messed around with a bit. How should I be doing this?

Many thanks
 
A

Arvin Meyer [MVP]

No the first line of code is in the button on the first form that opens the
second one. The second form's Open event, needs to read the OpenOrgs that's
passed from form number 1.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Steve Newport said:
Many thanks for that - its miore like I expected to do but I am a bit
confused by the second part. The first piece of code I entered using the
DoCmd.Openform was in the event for the button to press to open the second
form.

When you say the second forms Open event - exactly where do you mean?
Isn't
it the same block of code?

Arvin Meyer said:
If you use the last argument, called OpenArgs in the OpenForm Method, you
can get what you want.

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal, Me.[Supplier
ID]

Now, in the second form's Open event use a line like:

Me.txtSupplierID = Me.OpenArgs
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Steve Newport said:
Sorry basic question but I am going around in circles.

I have a simple supplier table with Supplier ID as key. I open a new
table
with a form in preparation to add a new record in the second table
(Contacts). Form opens OK and you can add entries but I want to copy
across
the Supplier ID so that it maintains the relationship. Tried several
ways
but
cant manage it.

The VB behind the relevant button that opens the form reads:

Private Sub CMD_AddContact_Click()
On Error GoTo Err_CMD_AddContact_Click

Dim stDocName As String
Dim stSupplierID As String

stDocName = "FRM_ContactsAdd"
stSupplierID = SupplierID

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal

Exit_CMD_AddContact_Click:
Exit Sub

Err_CMD_AddContact_Click:
MsgBox Err.Description
Resume Exit_CMD_AddContact_Click

End Sub

Which I have messed around with a bit. How should I be doing this?

Many thanks
 
S

Steve Newport

Thanks. Done that but I get a "Compile error" saying "Wrong number of
arguments or invalid property assignment".

I have entered both sets of codes as described.

Any ideas?

Arvin Meyer said:
No the first line of code is in the button on the first form that opens the
second one. The second form's Open event, needs to read the OpenOrgs that's
passed from form number 1.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Steve Newport said:
Many thanks for that - its miore like I expected to do but I am a bit
confused by the second part. The first piece of code I entered using the
DoCmd.Openform was in the event for the button to press to open the second
form.

When you say the second forms Open event - exactly where do you mean?
Isn't
it the same block of code?

Arvin Meyer said:
If you use the last argument, called OpenArgs in the OpenForm Method, you
can get what you want.

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal, Me.[Supplier
ID]

Now, in the second form's Open event use a line like:

Me.txtSupplierID = Me.OpenArgs
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Sorry basic question but I am going around in circles.

I have a simple supplier table with Supplier ID as key. I open a new
table
with a form in preparation to add a new record in the second table
(Contacts). Form opens OK and you can add entries but I want to copy
across
the Supplier ID so that it maintains the relationship. Tried several
ways
but
cant manage it.

The VB behind the relevant button that opens the form reads:

Private Sub CMD_AddContact_Click()
On Error GoTo Err_CMD_AddContact_Click

Dim stDocName As String
Dim stSupplierID As String

stDocName = "FRM_ContactsAdd"
stSupplierID = SupplierID

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal

Exit_CMD_AddContact_Click:
Exit Sub

Err_CMD_AddContact_Click:
MsgBox Err.Description
Resume Exit_CMD_AddContact_Click

End Sub

Which I have messed around with a bit. How should I be doing this?

Many thanks
 
A

Arvin Meyer [MVP]

As I look more carefully, there is. I copied and pasted your code which had
an extra argument, then added 1 more:

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal, Me.[Supplier
ID]

Should be:

DoCmd.OpenForm stDocName, , , , acFormAdd, acWindowNormal, Me.[Supplier ID]
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Steve Newport said:
Thanks. Done that but I get a "Compile error" saying "Wrong number of
arguments or invalid property assignment".

I have entered both sets of codes as described.

Any ideas?

Arvin Meyer said:
No the first line of code is in the button on the first form that opens
the
second one. The second form's Open event, needs to read the OpenOrgs
that's
passed from form number 1.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Steve Newport said:
Many thanks for that - its miore like I expected to do but I am a bit
confused by the second part. The first piece of code I entered using
the
DoCmd.Openform was in the event for the button to press to open the
second
form.

When you say the second forms Open event - exactly where do you mean?
Isn't
it the same block of code?

:

If you use the last argument, called OpenArgs in the OpenForm Method,
you
can get what you want.

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal,
Me.[Supplier
ID]

Now, in the second form's Open event use a line like:

Me.txtSupplierID = Me.OpenArgs
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

message
Sorry basic question but I am going around in circles.

I have a simple supplier table with Supplier ID as key. I open a new
table
with a form in preparation to add a new record in the second table
(Contacts). Form opens OK and you can add entries but I want to copy
across
the Supplier ID so that it maintains the relationship. Tried several
ways
but
cant manage it.

The VB behind the relevant button that opens the form reads:

Private Sub CMD_AddContact_Click()
On Error GoTo Err_CMD_AddContact_Click

Dim stDocName As String
Dim stSupplierID As String

stDocName = "FRM_ContactsAdd"
stSupplierID = SupplierID

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal

Exit_CMD_AddContact_Click:
Exit Sub

Err_CMD_AddContact_Click:
MsgBox Err.Description
Resume Exit_CMD_AddContact_Click

End Sub

Which I have messed around with a bit. How should I be doing this?

Many thanks
 
S

Steve Newport

Thanks. Seem to be getting closer now but it is now reporting another error
when opening the FRM_ContactsAdd form. It comes back and says "Compile Error:
Methof or data member not found". It then highlghts the txtSupplioerID
section of the command?

Arvin Meyer said:
As I look more carefully, there is. I copied and pasted your code which had
an extra argument, then added 1 more:

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal, Me.[Supplier
ID]

Should be:

DoCmd.OpenForm stDocName, , , , acFormAdd, acWindowNormal, Me.[Supplier ID]
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Steve Newport said:
Thanks. Done that but I get a "Compile error" saying "Wrong number of
arguments or invalid property assignment".

I have entered both sets of codes as described.

Any ideas?

Arvin Meyer said:
No the first line of code is in the button on the first form that opens
the
second one. The second form's Open event, needs to read the OpenOrgs
that's
passed from form number 1.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Many thanks for that - its miore like I expected to do but I am a bit
confused by the second part. The first piece of code I entered using
the
DoCmd.Openform was in the event for the button to press to open the
second
form.

When you say the second forms Open event - exactly where do you mean?
Isn't
it the same block of code?

:

If you use the last argument, called OpenArgs in the OpenForm Method,
you
can get what you want.

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal,
Me.[Supplier
ID]

Now, in the second form's Open event use a line like:

Me.txtSupplierID = Me.OpenArgs
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

message
Sorry basic question but I am going around in circles.

I have a simple supplier table with Supplier ID as key. I open a new
table
with a form in preparation to add a new record in the second table
(Contacts). Form opens OK and you can add entries but I want to copy
across
the Supplier ID so that it maintains the relationship. Tried several
ways
but
cant manage it.

The VB behind the relevant button that opens the form reads:

Private Sub CMD_AddContact_Click()
On Error GoTo Err_CMD_AddContact_Click

Dim stDocName As String
Dim stSupplierID As String

stDocName = "FRM_ContactsAdd"
stSupplierID = SupplierID

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal

Exit_CMD_AddContact_Click:
Exit Sub

Err_CMD_AddContact_Click:
MsgBox Err.Description
Resume Exit_CMD_AddContact_Click

End Sub

Which I have messed around with a bit. How should I be doing this?

Many thanks
 
A

Arvin Meyer [MVP]

The text box for your field "Supplier ID" is misspelled.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Steve Newport said:
Thanks. Seem to be getting closer now but it is now reporting another
error
when opening the FRM_ContactsAdd form. It comes back and says "Compile
Error:
Methof or data member not found". It then highlghts the txtSupplioerID
section of the command?

Arvin Meyer said:
As I look more carefully, there is. I copied and pasted your code which
had
an extra argument, then added 1 more:

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal, Me.[Supplier
ID]

Should be:

DoCmd.OpenForm stDocName, , , , acFormAdd, acWindowNormal, Me.[Supplier
ID]
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Steve Newport said:
Thanks. Done that but I get a "Compile error" saying "Wrong number of
arguments or invalid property assignment".

I have entered both sets of codes as described.

Any ideas?

:

No the first line of code is in the button on the first form that
opens
the
second one. The second form's Open event, needs to read the OpenOrgs
that's
passed from form number 1.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

message
Many thanks for that - its miore like I expected to do but I am a
bit
confused by the second part. The first piece of code I entered using
the
DoCmd.Openform was in the event for the button to press to open the
second
form.

When you say the second forms Open event - exactly where do you
mean?
Isn't
it the same block of code?

:

If you use the last argument, called OpenArgs in the OpenForm
Method,
you
can get what you want.

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal,
Me.[Supplier
ID]

Now, in the second form's Open event use a line like:

Me.txtSupplierID = Me.OpenArgs
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

message
Sorry basic question but I am going around in circles.

I have a simple supplier table with Supplier ID as key. I open a
new
table
with a form in preparation to add a new record in the second
table
(Contacts). Form opens OK and you can add entries but I want to
copy
across
the Supplier ID so that it maintains the relationship. Tried
several
ways
but
cant manage it.

The VB behind the relevant button that opens the form reads:

Private Sub CMD_AddContact_Click()
On Error GoTo Err_CMD_AddContact_Click

Dim stDocName As String
Dim stSupplierID As String

stDocName = "FRM_ContactsAdd"
stSupplierID = SupplierID

DoCmd.OpenForm stDocName, , , , acFormAdd, , acWindowNormal

Exit_CMD_AddContact_Click:
Exit Sub

Err_CMD_AddContact_Click:
MsgBox Err.Description
Resume Exit_CMD_AddContact_Click

End Sub

Which I have messed around with a bit. How should I be doing
this?

Many thanks
 

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

Similar Threads


Top