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

using VBA to call an insert statement 2

Status
Not open for further replies.

Sniipe

Programmer
Oct 9, 2006
115
IE
Code:
Dim sqlString As String

sqlString = "INSERT INTO Member (Member_ID, First_Name, Last_Name, Membership_Paid, Notes ,Telephone, Mobile, email, Address_Line_1, Address_Line_2, Address_Line_3, County, Country, Membership_Account, Family_ID) VALUES (" & Next_MemberID & ", '" & firstFamilyname & "', '" & Last_Name.Value & "','" & Membership_paid.Value & "', '" & Notes.Value & "', '" & Telephone.Value & "', '" & Mobile.Value & "', '" & email.Value & "', '" & Address_Line_1.Value & "', '" & Address_Line_2.Value & "', '" & Address_Line_3.Value & "', '" & County.Value & "', '" & Country.Value & "', 'Family', " & Next_FamilyID & ")"
                
DoCmd.RunSQL (sqlString)

I can't understand why this won't work. I've even stored the string in a text file and tried to execute it in the SQL of a query in Access.

It runs, but does not add a line to the table. and no errors.

Am I missing a step? Like commit, or something? Also is DoCmd.RunSQL the right command?

I'm 100% new to vba and access 2007, so any tips would be great. Thanks.

Its a DB I'm creating for a rally club for free.

FYI in the text file it looks like this:
Code:
"INSERT INTO Member (Member_ID, First_Name, Last_Name, Membership_Paid, Notes ,Telephone, Mobile, email, Address_Line_1, Address_Line_2, Address_Line_3, County, Country, Membership_Account, Family_ID) VALUES (386, '3a', 'h','11/11/2008', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'Family', 1)"
 
i m not familier with "Docmd.runsql"

but try
Code:
Currentdb.execute(sqlString)
 
I'll give that a try joe when I get home, but any idea why it won't insert the row when I use the MS access SQL command?
 

It appears you are attempting to move a text value into a date field (Membership_Paid). This could be causing a data mismatch error.

Check to see if you have set warnings to off.


Randy
 
thanks Randy, that was it, but how come I didn't get the warning? How do I turn it on?
 

I think it's here.....

Tools-->Options-->
Edit/Find tab
Confirm
Check the Action Queries box.





Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top