Anything wrong with this VB query code?

randommetalguy

Registered User.
Local time
Today, 15:04
Joined
Nov 25, 2008
Messages
52
Hey guys,

I've been using this same code all throughout my project but it is not working right now and I'm not getting any errors. Do you see anything wrong with it?

CurrentDb.Execute "Insert INTO tblFreeDesignForm " & _
"(FreeCordManufacturer, CordDiameter) VALUES " _
& " ('" & Me.txtCordManufacturer1.Value & "','" & Me.txtCordDiameter1.Value & "');"

I'm not getting any errors and when I debug and step into execution txtCordManufacturer1.value does indeed have a value. Also, tblFreeDesignForm also does have a field named FreeCordDiameter.

I don't see why it isn't working.
 
I would do the sql stuff in a string then execute the string. This way when you step through the code you can see what the sql string actually looks like. (Plus it's a little better programming practice :) )
 
Update:

I put the SQL into a string and executed the string. I thought it may have been because I was not assigning my table a primary key but that is not it.

Stepping through my code I found this. tblFreeDesignForm = Empty and FreeCordManufacturer = Empty even after I execute my Insert statement.
 
You may need to save the record then build the string.
 
Wow problem solved

In my other function I was saving the value of the textbox into a variable before executing the query.

So when I do

Dim freeCordManufacturer As String
freeCordManufacturer = Me.txtCordManufacturer1.Value
CurrentDb.Execute "Insert INTO tblFreeDesignForm (FreeCordManufacturer) VALUES ('" & freeCordManufacturer & "');"

it works.

I wonder why the me.txtCordManufacturer1 throws it off.
 
Cool. Now you could turn the action queries warning off with DoCmd.Setwarnings
 

Users who are viewing this thread

Back
Top Bottom