Question : VBA insert error

Hi Experts,

I am using the line of code below to insert records into a table. All words well until we hit the surname o'connor, then we get syntax error 3075, im assuming its the comma causing a problem, so how can I get around this?

d.Execute "insert into TblStudentProgress ([PSN],[CourseCode],[Forename],[Surname]) values('" & r!S_STUDENTREFERENCE & "','" & r!M_REFERENCE & "','" & r!P_FORENAMES & "' ,'" & r!P_SURNAME & "')"

Thanks,
Dean

Answer : VBA insert error

Alternatively keep the API call at the top as before and use:

Chris
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
Sub printExcelAttachments()
Dim itms As Object
Dim itm As Object
Dim sh As Object
Dim att As Object
Dim objFSO As Object
Dim objTempFolder As Object
Dim dlg As FileDialog
Dim xlApp As Object
Dim xlWB As Object
Dim xlWS As Object
 
    Set itms = Application.ActiveExplorer.Selection
 
    'On Error Resume Next
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTempFolder = objFSO.GetSpecialFolder(2)
    Set xlApp = CreateObject("excel.application")
    For Each itm In itms
        For Each att In itm.Attachments
            Select Case LCase(Right(att.Filename, Len(att.Filename) - InStrRev(att.Filename, ".")))
            Case "xls"
                att.SaveAsFile objTempFolder & "\" & att.Filename
                xlApp.workbooks.Open objTempFolder & "\" & att.Filename
                For Each xlWS In xlApp.workbooks(1).worksheets
                    xlWS.PrintOut
                Next
                xlApp.workbooks(1).Close False
            Case "xlsm"
                att.SaveAsFile objTempFolder & "\" & att.Filename
                xlApp.workbooks.Open objTempFolder & "\" & att.Filename
                For Each xlWS In xlApp.workbooks(1).worksheets
                    xlWS.PrintOut
                Next
                xlApp.workbooks(1).Close False
            Case "doc"
                att.SaveAsFile objTempFolder & "\" & att.Filename
                ShellExecute 0&, "Print", objTempFolder & "\" & att.Filename, 0&, 0&, 0&
            Case "pdf"
                att.SaveAsFile objTempFolder & "\" & att.Filename
                ShellExecute 0&, "Print", objTempFolder & "\" & att.Filename, 0&, 0&, 0&
            End Select
        Next
    Next
    xlApp.Quit
End Sub
Random Solutions  
 
programming4us programming4us