Solved

insert unbound text and combo box value into a table

Posted on 2008-10-28
10
1,531 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
Backup Your Microsoft Windows Server®

Backup 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: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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now