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

How can I get a recordset in to a table using VBA?

Status
Not open for further replies.

lewgar

Technical User
Feb 27, 2004
1
US
The goal is to overwrite a particular table in my Access 2000 db with the values from the collected recordset. I have collected the record set with success, however I am stumped at this point on how to get the recordset into my table.

The new table name can be anything, however for the sake of clarity, for now the table name is tblResults. The fields are exactly the same in the SQL db.

The reasons why I am not linking the tables is that this db exists in a high security Novell managed LAN, trusted connections (DSN, ODBC) are not allowed, my SQL Admin has given me one login, and there will be multiple users with there own local copy (no replication necessary, data is temporary). Hence, the connection string and the gathering of the data resolves my security problems.

The do loop is just to check to see if I collected the correct records.

Can anyone add the code to solve my problem?

The following is the code under the button on a form in an Access 2000 DB.

Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim cnnDiv As New ADODB.Connection
Dim rsDiv As New ADODB.Recordset
Dim objCom As New ADODB.Command
Dim iniRecCount As Integer

cnnDiv.Open "Driver={SQL Server};" & _
"Server=svrname;" & _
"Database=dbasename;" & _
"Uid=xxxxx;" & _
"Pwd=xxxxxx"

objCom.CommandType = adCmdStoredProc
objCom.ActiveConnection = cnnDiv
objCom.CommandText = "proDiv2"

Set rsDiv = objCom.Execute

iniRecCount = rsDiv.RecordCount

Do Until rsDiv.EOF = True

MsgBox rsDiv("RcNum").Value
rsDiv.MoveNext

Loop

cnnDiv.Close
Set cnnDiv = Nothing
Set rsDiv = Nothing


Exit_Command4_Click:
Exit Sub

Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top