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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding info from form and subform to table 1

Status
Not open for further replies.

kriza

IS-IT--Management
Nov 7, 2005
22
US
Please help.... I have a form containing a subform.. Within my form I have 1 textbox (textbox1) and in my subform, 1 combo box (CB1) and a text box (TB2).. what I'm trying to do is On Click, add the info from textbox1, CB1 and TB2 to a new table called student_course information..

I have added the following code to the command button:

Private Sub Command8_Click()
On Error GoTo Err_Command8_Click

Dim newclass As DAO.Database
Dim addclass As DAO.Recordset
Set newclass = CurrentDb()
Set addclass = newclass.OpenRecordset("Student_course Information")
addclass.AddNew
addclass!Student_Social_Security_Number = Me!Combo10
addclass!Course_ID = Me!Combo9
addclass!Course_Section = Me!Combo11
addclass.Update
addclass.Close
Set addclass = Nothing
Set newclass = Nothing


Exit_Command8_Click:
Exit Sub

Err_Command8_Click:
MsgBox Err.Description
Resume Exit_Command8_Click

End Sub

When I test, I get the following error message:

"compile error: user-defined type not defined".. any ideas on how to solve this will be very appreciated, it's been a long time since I used access and now it's driving me crazy :-(..

Thank you.
 
What version of Access are you using? If it is 2000, 2002, 2003, you more than likely need to add the DAO library to your References in VBA.

It would also help to know what the compiler is highlighting when it gives you the error.
 
You talk about two textboxes and one combobox, but your code reflects three combos.(?)
Using two textboxes and one combo, try:

Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("student_Course_info", dbOpenDynaset)
With rst
.AddNew
![Fieldfortextbox1] = Me![Textbox1]
![Fieldforcombo] = Forms![FrmName]![subformname].Form![CB1]
![Fieldfortextbox2] = Forms![FrmName]![subformname].Form![TB2]
.Update
End With
rst.Close
db.Close

Substitute your table name and field names where indicated.
Substitute your form name for FrmName and subform name for subformname.
Also, on the subform statements, Do Not Change the word FORM!
 
Thanks a lot guys, after adding the DAO library to my references and updating my code (thanks fneily), it worked perfectly... Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top