Advertisement

07.15.2008 at 07:04PM PDT, ID: 23568301
[x]
Attachment Details

Insert SQL statement using 2 tables and user input fields

Asked by BobRosas in Access Forms, SQL Query Syntax

Tags: SQL, Microsoft Access

tblOFInvDetail
   OFInvDetailID  Auto Key
   OfInvDetail  
   Company Code

tblOFInventory
   OFInventoryID  Auto Key
   OFInvTypeId    Not required
   OFInvDetailID   Numeric key from other table
   CompanyCode

The user wants to be able to Add a record to tblOFInventory but the record has to exist in tblOFInvDetail first.  My insert into tblOFInvDetail works but I need to then use the key created (in 1st tbl) as a field in tblOFInventory and Im not sure how to do that.  Im trying to insert into tblOFInventory the key from tblOFInvDetail where OFInvDetail = the users NewData (OFInvDetail) input.  


strNewSQL = "INSERT INTO tblOFInvDetail (OFInvDetail, CompanyCode) VALUES ('" & NewData & "','" & Me.txtHidCurrentCo & "')"
        DoCmd.SetWarnings False
        DoCmd.RunSQL strNewSQL
        Response = acDataErrAdded
***The Above all works.  A record is inserted.  The following does not.
Error = Syntax error, missing operator in query expression.

        strNewSQL2 = "INSERT INTO tblOFInventory ( OFInvDetailID, CompanyCode )        SELECT tblOFInventory.OFInvDetailID FROM tblOFInventory INNER JOIN tblOFInvDetail ON tblOFInventory.OFInvDetailID = tblOFInvDetail.OFInvDetailID
VALUES ('" & NewData & "','" & Me.txtHidCurrentCo & "')"
        'DoCmd.SetWarnings False
        DoCmd.RunSQL strNewSQL2
        DoCmd.SetWarnings True
        Response = acDataErrAdded

Thanks in advance.
Start Free Trial
 
Loading Advertisement...
 
[+][-]07.15.2008 at 07:47PM PDT, ID: 22012932

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.15.2008 at 07:50PM PDT, ID: 22012941

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.15.2008 at 07:53PM PDT, ID: 22012962

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.15.2008 at 07:59PM PDT, ID: 22012987

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Access Forms, SQL Query Syntax
Tags: SQL, Microsoft Access
Sign Up Now!
Solution Provided By: frankytee
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.16.2008 at 08:58AM PDT, ID: 22017231

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.16.2008 at 04:13PM PDT, ID: 22021021

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.16.2008 at 04:17PM PDT, ID: 22021039

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628