Solved

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

Posted on 2014-01-08
6
449 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
That worked!

THANK YOU!!!!!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

763 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

12 Experts available now in Live!

Get 1:1 Help Now