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
483 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 85
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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

688 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