Solved

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

Posted on 2014-01-08
6
455 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
[X]
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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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