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

Run-time error '3' - Help Please 2

Status
Not open for further replies.

LittleNick

Technical User
Jun 26, 2009
55
US
Greeting,
TheAceMan1 once showed me how to run command to insert a record into SQL table. I implemented and the codes ran fine. Now I have a very similar process that is attached to a different control, and when I run it I get a "run-time error '3': Closing delimiter not found for the string beginning at position250 in the command. The string begins with: ')}."
This is the code:
Code:
Dim db As DAO.Database, strSQL As String
    Dim CurrentUser As String
    
    CurrentUser = DLookup(……)
    Set db = CurrentDb

    strSQL = "Insert into tblUpdateTracking (Userid, datestamp, ValueBefore, ValueAfter, FileID, Description) " & _
             "Values ('" & CurrentUser & "', '" & Now() & "', '" & varBefore & "', '" & Me!OrderNumber & "', " & _
"'" & Me!FileID & "', '" & Me!Description & "')"
        DoCmd.RunSQL (strSQL)

The thing is not everytime I receive this message and when the message pops up, I notice it still write the record into SQL table. However, I just want to see what did I do wrong so that I can correct it.
Thanks for your suggestions or helps
 
I expect the issue is the delimiter for the date field. You might also have an issue if a text field contains an apostrophe.

Code:
Dim db As DAO.Database, strSQL As String
    Dim CurrentUser As String
    
    CurrentUser = DLookup(......)
    Set db = CurrentDb

    strSQL = "Insert into tblUpdateTracking (Userid, datestamp, ValueBefore, ValueAfter, FileID, Description) " & _
             "Values ('" & CurrentUser & "', #" & Now() & "#, '" & varBefore & "', '" & Me!OrderNumber & "', " & _
"'" & Me!FileID & "', '" & Me!Description & "')"
        DoCmd.RunSQL (strSQL)

Duane
Hook'D on Access
MS Access MVP
 
Thanks for your reply Duane(dhookom).
You are probably right. In the description field, there may contain an apostrophe. I will take out the date and the description file and run tests on it then I'll add the date back first and if I still do not encounter any problem, then I will also put the description back. That way, I can see what causes the error message.
I really appreciate your helps and thoughs
 
Replace this:
[tt]'" & Me!Description & "')"[/tt]
with this:
[tt]'" & Replace(Me!Description, "'", "''") & "')"[/tt]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top