Solved

Access: Using combo boxes to add information to a new table

Posted on 2014-01-08
6
453 Views
Last Modified: 2014-01-13
I am going to try to explain this the best I can, but I apologize if it isn't clear.

I am creating a form in Access. This particular form has three combo boxes that pull information from three different tables.

The first combo box is called "cmbTO".
It pulls its information from a table titled "TaskOrders."
There are three fields that it shows. toID, toNo, and todesc.

The next box is called "cmbSTO."  
It pulls its information from a table called "SubtaskOrders."
The fields in the SubtaskOrders table are stoID, toID, stoNo, and stoDesc
The combo box uses a query to filter the results in this box using the toID that is chosen in the first combo box, "cmbTO."

The last combo box is called "cmbStaff."
It gets its information from a table called "Staff"
The fields in the Staff table are staffID, Fname, and Lname.  
This combo box is not filtered.

What I need to have happen is this:
I want to choose the task order in the first combo box, then I want to choose a subtask order in the next combo box, and finally choose a staff member in the staff combo box.

Then I want to click on "Save" (a button I added), and have the ID numbers from the items I chose in the combo boxes, from the three different tables, get added to a fourth table.
The fourth table only has three fields: toID, stoID, and StaffID. I need it to store the combination of choices made in the form.

I have tried using the Control Source property to do this, but it messes up they query that I have in the cmbsto combo box.

Is there SQL or VBA code I should be using in the "save" button to do this?

Am I making it too complicated?

Any help is greatly appreciated.

(And my apologies for how confusing this is)
0
Comment
Question by:Megin
  • 3
  • 2
6 Comments
 

Author Comment

by:Megin
ID: 39766973
Yeah, I think I have that worked out on my form.

The problem is getting the values that I choose in those three combo boxes to save into a fourth table.

Also, unlike that example, the combo boxes I have now are all populated by three separate tables.

I want to have the IDs (primary keys from the three different tables) be saved in a  fourth table.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39767018
If that fourth table is included in your form's recordsource, then using the Control Source  Property of the combo boxes should do the trick.

Otherwise, if the fourth table is separate you can use an append query:

Dim strSQL as string
strSQL = "INSERT INTO tblFour (toID, stoID, StaffID) VALUES (" & me.cmbTO & ", " & Me.cmbSto & ", " & Me.cmbStaff & ")"
currentdb.execute strSQL, dbfailonerror

Open in new window


I'm assuming all of these IDs are numeric.

Double check and change table and field names to match those in your own database.
0
 

Author Comment

by:Megin
ID: 39777178
My apologies for taking so long to get back to you with my response. I got really busy with other things this week.

I put the code you sent into the "On Click" event for a button. It is telling me there is an error wtih the INSERT INTO statement.  This is what I wrote:

Dim strSQL As String
strSQL = "INSERT INTO StaffSTO (Staff ID, STOID, TOID) VALUES (" & Me.cmbStaff & ", " & Me.cmbSTO & ", " & Me.cmbTO & ")"
CurrentDb.Execute strSQL, dbFailOnError

Open in new window


Do I need to specify that StaffSTO is a table?
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39777248
No, that is implicit in the syntax.

I believe the problem is the space in the Staff ID field name.  It is generally best practice to avoid spaces and special characters in all of your naming conventions, but if they are present you have to delimit them.  Table and field names need to be enclosed in square brackets when spaces or special characters are involved:

strSQL = "INSERT INTO StaffSTO ([Staff ID], STOID, TOID) VALUES (" & Me.cmbStaff & ", " & Me.cmbSTO & ", " & Me.cmbTO & ")

Open in new window

"
0
 

Author Closing Comment

by:Megin
ID: 39777346
That worked!

THANK YOU!!!!!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

828 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