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
481 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
6 Comments
 
LVL 49

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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

807 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