UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Record Set From SQL Server To Datasheet Form, Any Version    
 
   
access2009eg
post Aug 15 2019, 03:24 AM
Post#1



Posts: 1,121
Joined: 19-February 08



Hello
friends

I don't know what I do is correct or not just try

I use this code to select records from SQL Server

I want to set this code to DataSheet form but not work with me

this error message appears in this line of code

CODE
                Set Me.Child1.Form.Recordset = rs

the object you entered is not a valid recordset property


CODE
                Dim adoConn As New ADODB.Connection
                Dim rs As New ADODB.Recordset
                'Trusted_Connection = Yes; if you use windows login if you want remove it add ' UID = addd ' Pwd= sdddsd
                adoConn.ConnectionString = "Provider=SQLNCLI10;Server=DESKTOP-SEV77GF\SQLSERVER_ZEZO;Database=xx;Trusted_Connection=yes;"
                adoConn.Open
                If adoConn.State = 1 Then
                Dim com As New ADODB.Command
                Dim recordAffecteds As Long
                Set com.ActiveConnection = adoConn
                com.CommandType = adCmdText
                com.CommandText = "select * from Contacts;"
                rs = com.Execute
                Do While Not rs.EOF
                Debug.Print vbTab & rs(0) & vbTab & rs(1)
                 rs.MoveNext
                Loop
                Set Me.Child1.Form.Recordset = rs
                adoConn.Close
                Set rs = Nothing
                Set adoConn = Nothing
                Set com = Nothing
                End If


--------------------
I would like to Thank you for your help
Go to the top of the page
 
PaulBrand
post Aug 15 2019, 04:09 AM
Post#2



Posts: 1,719
Joined: 4-September 02
From: Oxford UK


Try this:

Set Me.Child1.Form.RecordSource = rs

--------------------
Paul
Go to the top of the page
 
access2009eg
post Aug 16 2019, 02:43 PM
Post#3



Posts: 1,121
Joined: 19-February 08



PaulBrand


Not Worked also

--------------------
I would like to Thank you for your help
Go to the top of the page
 
projecttoday
post Aug 16 2019, 06:30 PM
Post#4


UtterAccess VIP
Posts: 10,966
Joined: 10-February 04
From: South Charleston, WV


Try adding New. If that doesn't work you can always use the SQL code.

--------------------
Robert Crouser
Go to the top of the page
 
access2009eg
post Aug 17 2019, 01:20 PM
Post#5



Posts: 1,121
Joined: 19-February 08



projecttoday
Where can I add your code?

--------------------
I would like to Thank you for your help
Go to the top of the page
 
projecttoday
post Aug 17 2019, 01:46 PM
Post#6


UtterAccess VIP
Posts: 10,966
Joined: 10-February 04
From: South Charleston, WV


New goes before rs.

Set rs = db.OpenRecordset("SQL code here", dbOpenDynaset)


--------------------
Robert Crouser
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    20th September 2019 - 08:06 PM