Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tables to Form back to Table 1

Status
Not open for further replies.

pmkieffe

Technical User
Jun 12, 2006
32
ID
Hi,

I have a form which uses a number of combo boxes and each one pulls a list of data from different tables. Can I have a user select data for each combo box, enter a number in a different combo box and on the click event have this information saved to a new table?

I am fairly new to access but have researched the recordset function so this may be a soulation. If someone responds and there is code I can use could you also define the variable terms in the code? I am also forseeing the problem of having to go back and correct user mistakes after the click event. Is this also possible?

Thank You,
pmkieffe
 
You would have your comboboxes and a textbox to enter the number and a "save" button. (command button) On the OnClick event of the button place:
Private SubCommand0_OnClick()
Dim DB As Database
Dim RS As Recordset
Dim strWhere As String

Set DB = CurrentDb()
Set RS = DB.OpenRecordset("MMCMainTable", dbOpenDynaset)
'strWhere = "[MMCNumber] = " & Chr(34) & Me![MMCNumber] & Chr(34)
'RS.FindFirst strWhere
'If RS.NoMatch Then
'MsgBox "No match found"
'Else
RS.AddNew
RS![FieldNameinTable] = Me![ComboboxName]
RS![FieldNameinTable2] = Me![ComboboxName2]
etc.
RS.Update
'End If
RS.Close
DB.Close
Set RS = Nothing
Set DB = Nothing
End Sub

Note: Commented lines are there if you are going to update a table. Then the RS.AddNew is changed to RS.Edit
 
Thank You,

But I just can't seem to get it to do anything. I get no error messages, but nothing seems to happen. To find out my mistake could you check my variables.

I want to use the form (pulling from other tables) to populate the table "Employee Hours"

For "MMCMainTable" I'm putting in the name of the table I want to populate. ("Employee Hours" - which is currently empty and different than the tables that the form is pulling from)

For FieldNameinTable, I'm putting in the Field name in "Employee Hours" (the table that i want to populate).

For ComboboxName, I'm putting in the name of the comboBox whose information I want to go into the field named above.

Are these correct?

Thanks,
pmkieffe
 
Fixed my problem. For some reason the code wasnt tied to the commandbox. Put in a new commandbox with the same code and it ran. Thank you very much.

-pmkieffe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top