Solved

Reference the value in a control on a subform for an INSERT INTO query? (Working around inability to INSERT INTO referencing a COLUMN.)

Posted on 2013-06-02
6
482 Views
Last Modified: 2013-06-02
Imagine you have a simple INSERT INTO statement as follows:

strSQL2 = "INSERT INTO tblInvoiceLine (invlinedescription, invlinepriceeach) SELECT linedescription, priceeach FROM tblOrderLine WHERE ordernumber = " & Me.orderid.Value

Open in new window


And now instead of, say linedescription or whatever you want to insert a stockcode which appears as column in my subform.

I understand I can not use a column with an INSERT INTO  statement and so I have created a text box (txtstockcode) on my form which references the column. It's control source is:

=[ordereditem].[column](1)

How do I reference the value in the control txtstockcode in my INSERT INTO query?

My form names are frmOrder and frmSalesOrderItems so I guess my statement will refer to something like:

SELECT '" & frmOrder.frmSalesOrderItems.txtStockCode.Value & "',

But that is where I am stuck!
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 39214280
It will be:

SELECT '" & frmOrder!NameOfYourSubformControlHoldingFormfrmSalesOrderItems.Form!txtStockCode.Value & "',

/gustav
0
 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
ID: 39214282
Change this portion:
Forms!frmOrder.Form!frmSalesOrderItems!txtStockCode
0
 
LVL 84
ID: 39214293
See this article:

http://support.microsoft.com/kb/113352

It refers to Access 97, but the same concepts apply to any version of Access.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Computer_Support_Norwich
ID: 39214294
Quick and beautiful. Thanks to you both.

cactus_data I did try this first:

SELECT '" & frmOrder!frmSalesOrderItems.Form!txtStockCode.Value & "'

But this errored 'Object Required' and then I tried this courtesy of IrogSinta which worked fine:

SELECT '" & Forms!frmOrder.Form!frmSalesOrderItems!txtStockCode & "'

Thanks!
0
 

Author Closing Comment

by:Computer_Support_Norwich
ID: 39214296
Thanks for quick and accurate response.
0
 

Author Comment

by:Computer_Support_Norwich
ID: 39214303
Hmm, now I have a problem with this code, but only because I did not explain myself fully. The answer given above does work okay where there is only a single line in my child table, but not for multiple lines. I will raise it as a new question!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question