J
Jo
Hi Everyone,
I am looking for some help in the following:
I have an access 2003 database. I am trying to provide an automation
facility where the users at the touch of a button can insert records from a
table to a sql server datatable. I am trying to use VBA and I also have set
up workgroup file for this so only users with this privilege can insert
records into sql server database. The schema of sql server looks similar to
that of access database where majority of the columns are text fields.
I get this error message when I am using odbc dsn-less connection:
Data source not found and no drivers specified which I couldn't understand
how?.
I changed this to OLE DB and tried but get this strange error: Record(s)
cannot be read; no read permission on contact
This is the code I have written to accomplish the task:
Dim oConn As ADODB.Connection
Dim oRS As ADODB.Recordset
Dim oComm As ADODB.Command
Dim objConn As New ADODB.Connection
Dim objRS As New ADODB.Recordset
Dim strConn As String
Dim strInsert As String
Dim strSelect As String
Dim strMDB As String
strMDB = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\Databases\contact.mdb;" & _
"Jet OLEDB:System Database=Security.mdw, admins, abc1234"
strSelect = "SELECT firstname,lastname,email,address,city,state,zip,phone
FROM contact"
objConn.Open strMDB
Set objRS = objConn.Execute(strSelect)
Set oConn = New ADODB.Connection
Set oRS = New ADODB.Recordset
Set oComm = New ADODB.Command
strConn = "Provider=sqloledb;Data Source=ODTESTServer;Initial
Catalog=Pubs;User Id=dummy;Password=abc"
'Driver={SQL Server}; Server=ODTESTServer; Database=Contact; Uid=dummy;
Pwd=abc"
oConn.Open strConn
oComm.ActiveConnection = oConn
oComm.CommandType = adCmdText
Do While Not objRS.EOF
strInsert = "INSERT INTO contacts
(firstname,lastname,email,address,city,state,zip,phone) VALUES" & _
"('" & objRS("firstname") & "', '" & objRS("lastname") & "', '" &
objRS("email") & "', '" & objRS("address") & "', " & _
"'" & objRS("state") & "', '" & objRS("zip") & "', '" & objRS("phone") &
"')"
oComm.CommandText = strInsert
oComm.Execute
objRS.MoveNext
Loop
Exit_UpdateAward:
oConn.Close
oRS.Close
Set oConn = Nothing
Set oRS = Nothing
Exit Sub
UpdateAwardErr:
MsgBox Err.Number & Err.Description
Resume Exit_UpdateAward
Any help is greatly appreciated! Thanks in advance
-Jo
I am looking for some help in the following:
I have an access 2003 database. I am trying to provide an automation
facility where the users at the touch of a button can insert records from a
table to a sql server datatable. I am trying to use VBA and I also have set
up workgroup file for this so only users with this privilege can insert
records into sql server database. The schema of sql server looks similar to
that of access database where majority of the columns are text fields.
I get this error message when I am using odbc dsn-less connection:
Data source not found and no drivers specified which I couldn't understand
how?.
I changed this to OLE DB and tried but get this strange error: Record(s)
cannot be read; no read permission on contact
This is the code I have written to accomplish the task:
Dim oConn As ADODB.Connection
Dim oRS As ADODB.Recordset
Dim oComm As ADODB.Command
Dim objConn As New ADODB.Connection
Dim objRS As New ADODB.Recordset
Dim strConn As String
Dim strInsert As String
Dim strSelect As String
Dim strMDB As String
strMDB = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\Databases\contact.mdb;" & _
"Jet OLEDB:System Database=Security.mdw, admins, abc1234"
strSelect = "SELECT firstname,lastname,email,address,city,state,zip,phone
FROM contact"
objConn.Open strMDB
Set objRS = objConn.Execute(strSelect)
Set oConn = New ADODB.Connection
Set oRS = New ADODB.Recordset
Set oComm = New ADODB.Command
strConn = "Provider=sqloledb;Data Source=ODTESTServer;Initial
Catalog=Pubs;User Id=dummy;Password=abc"
'Driver={SQL Server}; Server=ODTESTServer; Database=Contact; Uid=dummy;
Pwd=abc"
oConn.Open strConn
oComm.ActiveConnection = oConn
oComm.CommandType = adCmdText
Do While Not objRS.EOF
strInsert = "INSERT INTO contacts
(firstname,lastname,email,address,city,state,zip,phone) VALUES" & _
"('" & objRS("firstname") & "', '" & objRS("lastname") & "', '" &
objRS("email") & "', '" & objRS("address") & "', " & _
"'" & objRS("state") & "', '" & objRS("zip") & "', '" & objRS("phone") &
"')"
oComm.CommandText = strInsert
oComm.Execute
objRS.MoveNext
Loop
Exit_UpdateAward:
oConn.Close
oRS.Close
Set oConn = Nothing
Set oRS = Nothing
Exit Sub
UpdateAwardErr:
MsgBox Err.Number & Err.Description
Resume Exit_UpdateAward
Any help is greatly appreciated! Thanks in advance
-Jo