Solved

insert unbound text and combo box value into a table

Posted on 2008-10-28
10
1,534 Views
Last Modified: 2013-11-28
Hello,

There are several answers listed to this question, but they are too complicated for me.  Therefore can someone suggest a simple answer.  I am also very new to vb.

I have a form and a subform.  Within the subform I have one combo box and one text box.  When I input these values, I want to add a new record with these values to an existing table.  I have a command button to do this.

Thank you in advance
Joy
0
Comment
Question by:joygomez
  • 3
  • 2
  • 2
10 Comments
 
LVL 3

Expert Comment

by:coleventures
ID: 22827856
My example:
Created table (Table1) with two fields   combofield and textfield
Created form (frmTest) with two fields   combo1 and txtfield
Form also has a button that runs the query (Query1)

So, when you choose from the combobox and then enter into the text field you hit the button to run the APPEND QUERY (Query1) the info you selected/entered is appended to the destination table (Table1).

Here is the literal SQL code for the Query1

INSERT INTO Table1 ( combofield, textfield )
SELECT [forms]![frmTest]![combo1] AS Expr1, [forms]![frmTest]![txtfield] AS Expr2;


RGC
0
 
LVL 42

Accepted Solution

by:
dqmq earned 250 total points
ID: 22828158
Put this into your command button on_click event.  Replace uppercase words with the appropriate names.

dim SQL as string
sql = "insert into YOURTABLE (COL1, COL2)  values ('" & me.COMBOBOX & "','" me.TEXTBOX & "')"
currentdb.execute (SQL)



           
0
 

Author Comment

by:joygomez
ID: 22831035
dqmq,
this is what I am looking for.  however it gives me a syntax error.  here is the code.
My table name is "Scans Main" with two fields "Barcode" & "OS".  I have a form with a text field "Text12"  and a combobox "Combo14".  I do not see where I am going wrong.

Private Sub Command0_Click()
Dim SQL As String
sql = "insert into Scans Main (Barcode, OS)  values ('" & me.COMBO14 & "','" me.Text12 & "')"
CurrentDb.Execute (SQL)
End Sub
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:joygomez
ID: 22831091
dqmq,
I got passed the above problem, but now I have a new error "run time error 3134: Syntax error in Insert ito statement"
0
 

Author Comment

by:joygomez
ID: 22831188
i just realized that there were no points given.  how do i get these points to you.
0
 
LVL 3

Assisted Solution

by:coleventures
coleventures earned 250 total points
ID: 22831565
sql = "insert into Scans Main (Barcode, OS)  values ('" & me.COMBO14 & "','" me.Text12 & "')"

You forgot the '&' before me.Text12

sql = "insert into Scans Main (Barcode, OS)  values ('" & me.COMBO14 & "','" & me.Text12 & "')"
0
 
LVL 42

Expert Comment

by:dqmq
ID: 22831910
joygomez,
Communtiy Support can reassign points for you.  Contact them or post your intentions in this thread and they will take care of it.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

825 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