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!

Insert Into statement - keep getting blank lines inserted before

Status
Not open for further replies.

cutestuff

Technical User
Sep 7, 2006
162
CA
hi,

I don't know what's wrong, or why this is happening.
I have a form where a user selects several combo boxes, and then clicks a button. This in turn inserts the user's selections into a table.
My problem is this: the code works, but it inserts a blank row before the actual data. It happens only the first time the user tries to insert data (if they don't close the form and keep inserting more, no blank lines appear - except the first one).

Does anyone know why?
Here is the code behind the button:
Code:
'Copy the file to the specified folder in the Transfer Drive
            Set filesys = CreateObject("Scripting.FileSystemObject")
        
            'Check if file exists, if it does, copy file to appropriate folder
            If filesys.FileExists(txtPath) Then
                filesys.CopyFile txtPath, destPath
                
                MsgBox "File Upload Successful."
                
                'Insert values into main log
                stSQL = "INSERT INTO tblMainLog(LogID, SequenceID, Project, Company) VALUES ('" & tmpLogID & "', '" & sequenceNo & "', '" & Nz(Me![txtProject], 0) & "' , '" & Nz(Me![txtContractor], 0)"')"
                CurrentDb.Execute (stSQL) 'Execute the SQL-query
            
            Else
                MsgBox "File Not Found. The file you are trying to upload cannot be found.", vbOKOnly, "File Not Found!"
                
          End If

Appreciate any help you can give me.
thanks!
 
Try debugging it and see when the blanks are added.

Greetz,
Joeri
 
Since, before you instert data, you have:

MsgBox "File Upload Successful."

you should know every time about inserting your data into a table. Check your code for other Insert statements.


Have fun.

---- Andy
 
hi,

I've debugged it and found out that this statement alone adds the blank line:
Code:
stSQL = "INSERT INTO tblMainLog(LogID, SequenceID, Project, Company) VALUES ('" & tmpLogID & "', '" & sequenceNo & "', '" & Nz(Me![txtProject], 0) & "' , '" & Nz(Me![txtContractor], 0)"')"
I commented out
Code:
 CurrentDb.Execute (stSQL) 'Execute the SQL-query
.
I still don't understand. The execute AND stSQL statement inserts the actual data into the log, but the stSQL alone inserts a blank line. :( .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top