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
| Sub Test()
Debug.Print Application.CurrentProject.Path
Dim Base As String
With CreateObject("Adodb.connection")
Base = "C:\CGCPortail\MED_AC03.mdb"
.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Base & ";Persist Security Info=False"
insQuery = "INSERT INTO purchasearchive VALUES (" _
& TrouveTypeSql(PUID) & "," _
& TrouveTypeSql(cardNum) & "," _
& TrouveTypeSql(cardType) & "," _
& TrouveTypeSql(productID) & "," _
& TrouveTypeSql(Date) & "," _
& TrouveTypeSql(Number) & ");"
Debug.Print insQuery
.Execute insQuery
.Close
Debug.Print insQuery
End With
End Sub
Function TrouveTypeSql(V)
TrouveTypeSql = Trim("" & V)
If Trim("" & TrouveTypeSql) = "" Then TrouveTypeSql = "Null": Exit Function
If IsDate(TrouveTypeSql) = True And InStr(TrouveTypeSql, "/") <> 0 And InStr(TrouveTypeSql, ":") <> 0 Then TrouveTypeSql = "#" & Format(TrouveTypeSql, "yyyy-mm-dd hh:mm") & "#": Exit Function
If IsDate(TrouveTypeSql) = True And InStr(TrouveTypeSql, "/") <> 0 Then TrouveTypeSql = "#" & Format(TrouveTypeSql, "yyyy-mm-dd") & "#": Exit Function
If IsNumeric(Replace(TrouveTypeSql, ".", ",")) = True Then TrouveTypeSql = Replace(TrouveTypeSql, ",", "."): Exit Function
TrouveTypeSql = "'" & Replace(TrouveTypeSql, "'", "''") & "'"
End Function |
Partager