ADODB, SQL Back-End, Forms

Epax

Registered User.
Local time
Today, 17:47
Joined
Jan 10, 2007
Messages
14
Hello all,

Can someone expline how I can attach an ADODB Recordset ( backend is SQL) to a form. Here is the code I currently use:

Dim conn As New ADODB.Connection
Dim CMD As New ADODB.Command
Dim strSQL As String

Set conn = New ADODB.Connection
Set CMD = New ADODB.Command
Set ImportRs = New ADODB.Recordset



conn.ConnectionString = "driver={SQL Native Client};server=209.242.27.132\SQLEXPRESS;databasename=FASDB;Persist Security Info=True;Uid=elewis;Pwd=vash.0115;"

conn.Open
CMD.ActiveConnection = conn
CMD.CommandText = "Select companyname from company;"
CMD.CommandType = adCmdText

ImportRs.LockType = adLockOptimistic
ImportRs.CursorType = adOpenKeyset
ImportRs.CursorLocation = adUseClient

Set ImportRs = CMD.Execute
ImportRs.MoveFirst

>>>>>>> Me.Recordset = ImportRs.Clone

Here is my problem ^^^^^


Thank you for your time. Cheers!
 
Try this instead -
Code:
Dim conn As New ADODB.Connection
Dim strSQL As String
Dim ImportRS As ADODB.Recordset

Set conn = New ADODB.Connection
Set ImportRS = New ADODB.Recordset

strSQL = "Select companyname FROM company"

conn.ConnectionString = "driver={SQL Native Client};server=209.242.27.132\SQLEXPRESS;databasen ame=FASDB;Persist Security Info=True;Uid=elewis;Pwd=vash.0115;"

conn.Open


ImportRS.Open strSQL, conn, adOpenKeyset, adLockOptimistic

ImportRS.MoveFirst

Set Me.Recordset = ImportRS
 
Last edited:
Bob,
Thanks for your help.
I only post this part so others have the full correct answer:

Me.Recordset = ImportRS

should be

Set Me.Recordset = ImportRS
 

Users who are viewing this thread

Back
Top Bottom