473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Running a Query from a Combo box

Okay so i have been trying to do something within Access and cannot seem to get it to work.

Heres what i have:

i have 3 tables set up that are identical. The only difference is that the tables have different titles as they are databases for different customers.

I have a form called form1 that has:

A combo box (combo2) set up with the name of the three customer tables.

I have 4 text boxes(text1-text4) that are blank.

WHAT I WANT:
i was wondering if there was a way to be able to select the name of the customer table from the combo box, and then type data into the 4 text boxes. Then click a button that appends to the selected table the data of the text boxes into fields 3-6 (text box 4 would go in field 3, 5 into 6 ect ect...)

Is this possible. I know that i can create 3 different append queries but i was wondering if there was an easier way. My reasoning for this is that this sequence is set up as a pilot for three customers but will soon be expanded using all 250 of our customers. Do i really need to create 250 append queries or is there a short cut?

thanks in advance,
Kent
Sep 27 '10 #1

✓ answered by MMcCarthy

There was an extra comma at the end.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO " & Me!Combo23 & " ([RMA #], [Quote ID], [Credit(USD)], [Credit(#)], [Credit(Euros)], [Credit(CAD)], [Credit(YEN)], [Credit(AUD)]) VALUES(" & Me!Text5 & ", '" & Me!Text7 & "', " & Me!Text13 & ", " & Me!Text19 & ", " & Me!Text17 & ", " & Me!Text15 & ", " & Me!Text11 & ", " & Me!Text9 & ")"

7 2146
MMcCarthy
14,534 Expert Mod 8TB
I think what you need is something like the following code presumably behind a command button.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdButton1()
  2.  
  3.     DoCmd.RunSQL "INSERT INTO " & Me!ComboBox1 & " (Field1, Field2, Field3) VALUES(" & Me!txtBox1 & ", " & Me!txtBox2 & ", " & Me!txtBox3 & ")"
  4.  
  5. End Sub
Notes:
  • Replace Field1, Field2, etc with your actual Field Names. This assumes each table has the same field names.
  • Replace ComboBox1 with the name of your combo box and likewise for txtbox1 etc.
  • There are also rules for passing values.

    If the field a value is being passed to has a datatype of text then you will have to add a single quote before and after txtbox control '" & Me!txtBox1 & "' and if the field has a date/time data type you have to add a hash #" & Me!txtBox1 & "#
Sep 28 '10 #2
First of all thank you MMcCarthy for helping me with my problem. So i did what you said but i am recieving an error that says "systax error in INSERT INTO statement". I am working in Access 2007 if that matters. I added more fields so the code that i am working on looks as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command25_Click()
  2. On Error GoTo Command25_Click_Err
  3.  
  4.  
  5.  
  6.     DoCmd.RunSQL "INSERT INTO " & Me!Combo23 & " (RMA #, Quote ID, Credit(USD), Credit(#), Credit(Euros), Credit(CAD), Credit(YEN), Credit(AUD)) VALUES(" & Me!Text5 & ", '" & Me!Text7 & "', " & Me!Text13 & ", " & Me!Text19 & ", " & Me!Text17 & ", " & Me!Text15 & ", " & Me!Text11 & ", " & Me!Text9 & ",)"
  7.  
  8.  
  9.  
  10. Command25_Click_Exit:
  11.     Exit Sub
  12.  
  13. Command25_Click_Err:
  14.     MsgBox Error$
  15.     Resume Command25_Click_Exit
  16.  
  17. End Sub
Any idea how to fix this error?
Sep 28 '10 #3
MMcCarthy
14,534 Expert Mod 8TB
Hi Kent

Access doesn't like spaces in field names and it doesn't like a number of other characters including I think brackets. To get around this enclose the field names in square brackets as follows:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO " & Me!Combo23 & " ([RMA #], [Quote ID], [Credit(USD)], [Credit(#)], [Credit(Euros)], [Credit(CAD)], [Credit(YEN)], [Credit(AUD)]) VALUES(" & Me!Text5 & ", '" & Me!Text7 & "', " & Me!Text13 & ", " & Me!Text19 & ", " & Me!Text17 & ", " & Me!Text15 & ", " & Me!Text11 & ", " & Me!Text9 & ",)"
Sep 28 '10 #4
Once agian thanks for the help, however,
Im still getting the same "systax error in INSERT INTO statement" message.

Any other ideas?
Sep 28 '10 #5
MMcCarthy
14,534 Expert Mod 8TB
There was an extra comma at the end.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO " & Me!Combo23 & " ([RMA #], [Quote ID], [Credit(USD)], [Credit(#)], [Credit(Euros)], [Credit(CAD)], [Credit(YEN)], [Credit(AUD)]) VALUES(" & Me!Text5 & ", '" & Me!Text7 & "', " & Me!Text13 & ", " & Me!Text19 & ", " & Me!Text17 & ", " & Me!Text15 & ", " & Me!Text11 & ", " & Me!Text9 & ")"
Sep 28 '10 #6
I should have noticed that. Thanks. It works!!!
I have once more question for you, using the same combo box (combo23, is there a way to use a new command button that i can use to sum the fields in the table. For example i want to sum fields : Credit(USD), Credit(#), Credit(Euros), Credit(CAD), Credit(YEN), Credit(AUD).

Can this be done?
Sep 28 '10 #7
MMcCarthy
14,534 Expert Mod 8TB
Ask it as a separate question. We don't allow multiple questions in a thread as it gets too confusing. Just start a new thread.
Sep 28 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: tukaram.thatikonda | last post by:
Hi Guys, I have written a small windows application in VB.Net to test ADO.Net performance while executing long running query. The query works most of the time but fails sometime. I am trying...
1
by: ian.davies52 | last post by:
I'm having a problem running a query. I get the "too many fields" error message, but I only have 162 fields in the query and I thought the limit was 255. The problem query (Query1) is based on...
4
by: Kory | last post by:
How do you stop a long running query with a SQLConnection or SQLCommand? Calling Close on either just waits until the query is done. Is there a way to stop it? The following on a long query ...
2
by: John | last post by:
Hi Is it possible to do run a select query on a dataset from a web method using a dataadapter? A code example would be great. If not, how can we grab hold of the remote dataset data in a local...
6
by: johntarr | last post by:
I hope I am not asking about something that has been done before, but I have searched and cannot find an answer. What I am trying to do is to run a query, and then perform some logic on the...
8
by: John | last post by:
Hi I am using the below code to run a sql on an underlying access table; insStr = "INSERT INTO ( Action, , , Request_Date ) " & _ "VALUES (""Modify Client"", 93, ""Administrator"", Now())"...
0
by: Prabhakar78 | last post by:
How to tune long running query?Please any one can provide me the steps to tune long running query in DB2 V9.1.0 and the environment is AIX (OS)
2
by: hafner | last post by:
Hello all, I have an extremely simple query I'm running on a linked table. However, when I run it (primarily, I'm exporting to a .txt file, but the behavior persists even if I run the query), it...
2
ddtpmyra
by: ddtpmyra | last post by:
I have query combo but I notice It only save the first words. For instance, Commitee Members Commitee Officials It only pick the word 'Committee' and not the next word when I get the...
6
by: sarah2855 | last post by:
Hello everyone, I'm running a Make-Table Query in Access. They was working fine up intill an hour ago and suddenly now that I'm running the query , I keep getting this error message: Can not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.