Posted on 2014-04-16
Last Modified: 2014-04-16
Experts, I am trying to create an insert query. I need to insert some data from a user form and then need to get some data from two other tables. I cannot figure this out. Is what I am trying to do possible?

Please Help...
        strSql = "INSERT INTO ProjectProfile (ProjectName,QuoteNumber,LogDate,Freight,FOB,LineItems,GroupTotal,TotalList,IncludeService,Discount," & _
                 "QuoteLife,Onsite,OffSite,Training,Overtime,Saturday,SaturdayOvertime,Sunday,Hold,Travel,WeekendTravel,Mileage,Software) " & _
                 "VALUES (" & _
                 "'" & txtProjectName.Text & "','" & txtQuoteNumber.Text & "',#" & Today & "#),(" & _
                 "SELECT Freight,FOB,Lineitems,GroupTotal,TotalList,IncludeService,Discount,QuoteLife FROM QuoteDefaults),(" & _
                 "SELECT Onsite,Offsite,Training,Overtime,Saturday,SaturdayOvertime,Sunday,Hold,Travel,WeekendTravel,Mileage,Software FROM ServiceRates)"

Open in new window

Question by:Basicfarmer
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
LVL 22

Expert Comment

ID: 40004173
your question is a little unclear...
 are you asking for how to write the following query in VB.NET  Syntax ?

Expert Comment

ID: 40004181
write a single select statement where you can pass first 3 values from the form values.
something like this..
Insert into ProjectProfile(columns...)
select txtProjectName.Text, txtQuoteNumber.Text, other columns...
FROM table

Author Comment

ID: 40004198
Plusone3055, I was hoping that my attempt to create this query would show what I wanted to do. This query does not work.  How should this be written so it works? I dont need any vb specifc syntax im just creating the string.
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

LVL 52

Accepted Solution

Carl Tawn earned 500 total points
ID: 40004210
It should be possible (depending on the database you are using).

Try something like:
strSql = "INSERT INTO ProjectProfile 
SELECT '" & txtProjectName.Text & "', '" & txtQuoteNumber.Text & "', #" & Today & "#, t1.Freight,t1.FOB,t1.Lineitems,t1.GroupTotal,t1.TotalList,t1.IncludeService,t1.Discount,t1.QuoteLife,
				 FROM QuoteDefaults t1, ServiceRates t2"

Open in new window


Author Comment

ID: 40004214
Jayakrishnabh, this gave me an error at "Select Freight".
        'strSql = "INSERT INTO ProjectProfile (ProjectName,QuoteNumber,LogDate,Freight,FOB,LineItems,GroupTotal,TotalList,IncludeService,Discount," & _
        '         "QuoteLife,Onsite,OffSite,Training,Overtime,Saturday,SaturdayOvertime,Sunday,Hold,Travel,WeekendTravel,Mileage,Software) " & _
        '         "SELECT " & _
        '         "'" & txtProjectName.Text & "','" & txtQuoteNumber.Text & "',#" & Today & "#," & _
        '         "SELECT Freight,FOB,Lineitems,GroupTotal,TotalList,IncludeService,Discount,QuoteLife FROM QuoteDefaults," & _
        '         "SELECT Onsite,Offsite,Training,Overtime,Saturday,SaturdayOvertime,Sunday,Hold,Travel,WeekendTravel,Mileage,Software FROM ServiceRates"

Open in new window


Author Closing Comment

ID: 40004225
That was exactly what I needed, Thanks Carl...
LVL 44

Expert Comment

ID: 40004226
>>I need to insert some data from a user form and then need to get some data from two other tables.

Is the data being inserted ONLY from the user form?
The get some data - is that after the INSERT have completed?

If the answer to both of the above questions is true then you need to perform the action in two (or more) distinct steps.  First run the INSERT SQL command then the SELECT command(s) to return the data.

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Stop Git from being my repository 1 47
sort Multi-dimensional array 6 43
MessageBox Appear behind a form in Runtime 1 29
Convert a string to date 4 40
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video teaches viewers about errors in exception handling.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

739 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