Insert string to table with sql statement

Cereldine

Registered User.
Local time
Today, 08:47
Joined
Aug 4, 2005
Messages
71
Hi, im building myself a error handler and part of it is to record the error details in a logging table. I have a function that flags up error number, description and location in a message box. How do i take these strings and long ints and record them into a table. Below is a snippet of code ive been trying, the problem is in my sql statement, any help appreciated!

ErrorLog = True

strMsg = strMsg & "There has been an error in the application." & vbCrLf & vbCrLf ''vbCRLF (Visual Basic Carriage Return Line Feed) is the VB shortcut for Chr(13) & Chr(10), ;
strMsg = strMsg & "Error Number: " & lngErrNum & vbCrLf
strMsg = strMsg & "Error Description: " & strErrDesc & vbCrLf
strMsg = strMsg & "Error Location: " & strWhereFrom & vbCrLf

strMsg = strMsg & "This error has been inputted into the error handling log table" & vbCrLf & vbCrLf
strMsg = strMsg & "Any further problems contact on.your.own@xxx.gov"

MsgBox strMsg, vbInformation, "Error Log."

sql = "INSERT INTO Error_handling_table (Error_Number,Error_Description,Error_Location ) VALUES (lngErrNumber,strErrDesc,strWhereFrom) "
DoCmd.RunSQL (sql)
 
well, seems to me you have some syntax issues to start with.

sql = "INSERT INTO Error_handling_table ([Error_Number],[Error_Description],[Error_Location] ) VALUES ( '" & lngErrNumber & "' ,'" & strErrDesc & "' , '" & strWhereFrom &"') "
DoCmd.RunSQL sql
thats the way I do this typically.

remember, when you make an sql statement, you're building a string. so you can't put variable names into it directly, because vb just thinks its text.
 

Users who are viewing this thread

Back
Top Bottom