RunSQL INSERT

sstreet

Access Demon
Local time
Today, 20:33
Joined
Dec 5, 2002
Messages
50
I am trying to run an insert query using the following code:
Code:
DoCmd.RunSQL "INSERT INTO Software ( PCID, Name, Version ) VALUES ( '" & Me.txtPCID & "', '" & CStr(lngSoftware) & "', '" & CStr(lngVersion) & "');"

The program loops through the registry extracting software information and runs the query after each loop. The query works but only inserts data where all the fields contain values.

Any ideas how I can get around this?


Thanks in advance.
 
Do your fields from the SOFTWARE table accept Null values?
 
s,

You have to either get the table in Design View and allow for Null values.

Or you can use the Nz() function to provide a suitable default value.

Wayne
 
The table does accept null values, but I think the query only inserts a record if all the fields have a value.
 
Resolved

Thanks, I used the Nz() function when looping through the registry.
 
for future reference, it's just good programming etiquette to put your SQL statement in it's only string variable.

this provides for several things: it increases readability, it helps make your code adaptable, it helps reduce reader seek/debug time.

in such a short snipet as this is, readability is not a problem, but still, it's good practice none the less =)


Glad to see the Nz() function, that wayne suggested, worked for you
 

Users who are viewing this thread

Back
Top Bottom