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

Please help with this Easy Question

Status
Not open for further replies.

sksbizkit

Programmer
Jan 11, 2007
9
US
All that i'm trying to do is INSERT values from a form into a table called "DEPENDENTS" using access/sql...here is the code..PLEASE HELP


Private Sub cmdAddDependent_Click()
Dim sSql As String
Dim dbThis As Database
'
Set dbThis = Access.CurrentDb



sSql = "INSERT INTO DEPENDENTS VALUES('" & cboAssociate2.Value & "','" & cboAssociate2.Value & "', '" & txtFirstName.Value & "', '" & txtLastName.Value & "', '" & txtB.Value & "'," & txtNumber.Value & ")"



Dim cQry As QueryDef
Set cQry = dbThis.QueryDefs("TEMP", sSql)
cQry.Execute


End Sub
 
Why using a QueryDef for an action query ?
You may try either this:
DoCmd.RunSQL sSql
or this:
dbThis.Execute sSql

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
changed my code to this, and it still doesnt update my table...

Private Sub cmdAddDependent_Click()
Dim sSql As String
Dim dbThis As Database
'
Set dbThis = Access.CurrentDb



sSql = "INSERT INTO DEPENDENTS VALUES('" & cboAssociate2.Value & "','" & cboAssociate2.Value & "', '" & txtFirstName.Value & "', '" & txtLastName.Value & "', '" & txtB.Value & "'," & txtNumber.Value & ",15)"


dbThis.Execute sSql




End Sub
 
What are ALL the fields (name+datatype) of DEPENDENTS ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I even tryed to change the insert statement around to this....


sSql = "INSERT INTO DEPENDENTS(DEPEND_ID, DEPEND_ASSOC_ID, DEPEND_FNAME,DEPEND_LNAME, DEPEND_DOB, DEPEND_AGE, DEPEND_RELATE_TYP) VALUES ('" & cboAssociate2.Value & "','" & cboAssociate2.Value & "', '" & txtFirstName.Value & "', '" & txtLastName.Value & "', '" & txtB.Value & "'," & txtNumber.Value & ",15)
 
Replace this:
dbThis.Execute sSql
with this:
Debug.Print sSql

Then copy the ouput produced in the debug window and paste it in the SQL view pane of a brand new query.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
sksbizkit - Do you think by posting the same question 3 different times you're adding any value to this site or your learning process? You don't even change the question any to make it different in any way....

Thread701-1330801 posted 10:40
Thread701-1330808 posted 10:57




Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for database developers:
The Fundamentals of Relational Database Design
Understanding SQL Joins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top