• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 461
  • Last Modified:

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

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
Megin
Asked:
Megin
  • 3
  • 2
1 Solution
 
MeginAuthor Commented:
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
 
mbizupCommented:
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
 
MeginAuthor Commented:
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
 
mbizupCommented:
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
 
MeginAuthor Commented:
That worked!

THANK YOU!!!!!!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now