Results 1 to 4 of 4
  1. #1
    GarrettB is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Location
    BC, Canada
    Posts
    5

    Newbie SQL question regarding how to use OpenRecordSet

    Hi




    This is my first time trying to use code to access a table in my database.
    I followed examples I can find online, but I am getting a compile error for the most basic of functions;
    Here is my code:


    Code:
    Private Sub Cmd_Button1_Click()
        
        Dim dbs1 As DAO.Database
        Dim rst1 As DAO.Recordset
        Dim sql1 As String
        
        Set dbs1 = CurrentDb
        sql1 = "SELECT * FROM Tbl_Demo1"
        rst1 = dbs1.OpenRecordset(sql1)
    
    
    End Sub
    When I click the button for this code to run, I get "Compile error: Invalid use of property" for this line (rst1 is highlighted):


    Code:
    rst1 = dbs1.OpenRecordset(sql1)
    So I think there is some fundamental knowledge / bit of info that I am missing


    Any help appreciated, thanks

    Garrett

  2. #2
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code:
     rst1 = dbs1.OpenRecordset(sql1)
    You need to use the "SET" keyword
    Code:
     SET rst1 = dbs1.OpenRecordset(sql1)

  3. #3
    GarrettB is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Location
    BC, Canada
    Posts
    5
    Perfect, thanks Steve

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Happy to help...

Please reply to this thread with any new information or opinions.

Similar Threads

  1. newbie question
    By sbrady19 in forum Access
    Replies: 4
    Last Post: 02-10-2015, 01:25 PM
  2. Simple openrecordset Question
    By Paul H in forum Programming
    Replies: 11
    Last Post: 04-08-2014, 05:14 PM
  3. Newbie question
    By Patience in forum Queries
    Replies: 4
    Last Post: 11-24-2010, 02:18 AM
  4. vba question from newbie
    By ninachopper in forum Access
    Replies: 17
    Last Post: 07-29-2010, 01:22 PM
  5. Newbie question
    By The_Dude in forum Programming
    Replies: 2
    Last Post: 12-23-2007, 07:11 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums