R
ryguy7272
About two weeks ago, or thereabouts, someone gave me this code (below):
Private Sub btnSendToDB_Click()
Dim usrName As String
Dim dbConnection As ADODB.Connection
Dim recordSet As ADODB.recordSet
Dim strSQL As String
Set dbConnection = New ADODB.Connection
Set recordSet = New ADODB.recordSet
'The variable that'll hold the data within txtBoxName
usrName = Me.txtBoxName.Value
strSQL = "INSERT INTO Names [Name] VALUES '" & usrName & "'"
dbConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source
=C:\Documents and Settings\rshuell\Desktop\Access Models\Diego_Reports.mdb"
dbConnection.CursorLocation = adUseClient
' This will open up the recordSet, using the SQL statement and the
dbConnection - Connection.
recordSet.Open strSQL, dbConnection
'Close of the connection.
dbConnection.Close
Set dbConnection = Nothing
End Sub
I can’t seem to find that post now, so I guess I will start another.
Anyway, I think the code is mostly in tact, but I get an error that reads
‘Syntax error in INSERT INTO statement’.
This line is yellow:
recordSet.Open strSQL, dbConnection
I’m not sure what is causing the error, but I’d appreciate it if someone can
tell me.
Regards,
Ryan---
Private Sub btnSendToDB_Click()
Dim usrName As String
Dim dbConnection As ADODB.Connection
Dim recordSet As ADODB.recordSet
Dim strSQL As String
Set dbConnection = New ADODB.Connection
Set recordSet = New ADODB.recordSet
'The variable that'll hold the data within txtBoxName
usrName = Me.txtBoxName.Value
strSQL = "INSERT INTO Names [Name] VALUES '" & usrName & "'"
dbConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source
=C:\Documents and Settings\rshuell\Desktop\Access Models\Diego_Reports.mdb"
dbConnection.CursorLocation = adUseClient
' This will open up the recordSet, using the SQL statement and the
dbConnection - Connection.
recordSet.Open strSQL, dbConnection
'Close of the connection.
dbConnection.Close
Set dbConnection = Nothing
End Sub
I can’t seem to find that post now, so I guess I will start another.
Anyway, I think the code is mostly in tact, but I get an error that reads
‘Syntax error in INSERT INTO statement’.
This line is yellow:
recordSet.Open strSQL, dbConnection
I’m not sure what is causing the error, but I’d appreciate it if someone can
tell me.
Regards,
Ryan---