Results 1 to 13 of 13
  1. #1
    JB510's Avatar
    JB510 is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Ontario
    Posts
    44

    Trouble opening an Older version of Access and creating a record set.

    I am using the latest version of MS Access, and trying to open an older version of Access and create a record set but I get an error.
    Stepping though my code, I get an error when I try to set the query:
    Set rs = db.OpenRecordset("SELECT * FROM RMA_Serial_Numbers WHERE Customer_SerialNum = '" & SN & "'")
    it will give a Run-time error '91': Object variable or with block variable not set. What am I doing wrong??

    Below is the code so far..
    Dim accessApp As Object ' Late binding - allows using different Access versions
    Dim db As Object
    Dim rs As Object
    Dim strSQL As String
    Dim SN As String
    Dim Clientele As String



    Clientele = "C:\Path\to\ctel.mdb"

    ' Create an instance of MS Access application
    Set accessApp = CreateObject("Access.Application")

    ' Open the old version of Access database
    accessApp.OpenCurrentDatabase Clientele

    ' Show the Access window
    accessApp.Visible = True

    ' Get reference to the opened database
    Set db = accessApp.CurrentDb

    'Open recordset
    Set rs = db.OpenRecordset("SELECT * FROM RMA_Serial_Numbers WHERE Customer_SerialNum = '" & SN & "'")

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,016
    Not posting within code tags to start with.

    have you checked the local variables?, are they set correctly?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    Do you get any details with that error?
    Have you tried stepping through your code to identify the line where error occurs?

    ??Where in Ontario??

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,016
    Code works for me, in that it runs the query. However I am only on 2007.

    Code:
    Sub TestAnotherDB()
    Dim accessApp As Object ' Late binding - allows using different Access versions
    Dim db As Object
    Dim rs As Object
    Dim strSQL As String
    Dim SN As String
    Dim Clientele As String
    
    
    Clientele = "F:\Users\Paul\Documents\Bibbys.mdb"
    
    
    ' Create an instance of MS Access application
    Set accessApp = CreateObject("Access.Application")
    
    
    ' Open the old version of Access database
    accessApp.OpenCurrentDatabase Clientele
    
    
    ' Show the Access window
    accessApp.Visible = True
    
    
    ' Get reference to the opened database
    Set db = accessApp.CurrentDb
    
    
    'Open recordset
    Set rs = db.OpenRecordset("SELECT * FROM Crew WHERE ID = 23")
    
    
    End Sub
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    Hi Paul,

    Glad it worked ok for you on 2007. Perhaps OP/JB510 could tell us in what version his .mdb was created.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,016
    My mdb would be from 2003 Access.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    JB510's Avatar
    JB510 is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Ontario
    Posts
    44
    Sorry about posting the code. I'm new at this forum and will look up how to properly..

    The old database was running with Access 2003.
    I am currently using the latest with Office 365 to try to just read the info from the old database.

    I am stepping though the code with the F8 key and it errors out on that line.
    I know the variables in the "SELECT * FROM RMA_Serial_Numbers WHERE Customer_SerialNum = '" & SN & "'" command should work as it currently is working on another machine running an older version of Excel in a XP emulator. (Thus I am creating a new database program to do alot of little jobs I had excel doing.)

    I am working in Guelph ON but live in Hamilton ON.

  8. #8
    JB510's Avatar
    JB510 is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Ontario
    Posts
    44
    I had multiple programs I run in an XP emulator on another machine.
    old 2003 Excel programs and MSAcess.

    I am making a new Office 365 MS Access database but still need the old info for old record pulling.
    I am currently trying to read a 2003 MS Accces .xls file using similar code but am running into runtime errors.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,016
    I would be checking your objects have been set correctly?
    I would likely just import the old data into the new db, then remove when no longer required.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,824
    I'm thinking that CurrentDb is a copy of the db that is related to the User Interface (UI), in which case that would be the db where you're running the code from, which shouldn't work. Perhaps Set db = accessApp.dbEngine(0)(0) would work for this?
    I also wonder if there aren't easier ways, such as linking or importing the tables, r TransferSpreadsheet method between db's.

    As for code tags, it's the # button on the posting toolbar.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    JB510's Avatar
    JB510 is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Ontario
    Posts
    44
    I tried
    Code:
    Set db = accessApp.dbEngine(0)(0) would work for this?
    it now gives Run-time Error 3265 Item not found in this collection.

    It has something to do with setting db.. With the original code
    Code:
    Set db = accessApp.CurrentDb
    it did not compain about the line after stepping though it, but if you hovered over it would say db - Nothing
    ..

    Oh and I did some research and the old database was 1997. (.mdb)
    The file is currently still being used so I can't transfer the files over.. (They are using it in an XP window for now with a 2003 version of MSAcces.)

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,016
    Quote Originally Posted by JB510 View Post
    it did not compain about the line after stepping though it, but if you hovered over it would say db - Nothing
    That is why I said 'inspect your variables/check your objects'
    As I mentioned your first code shown, worked for me.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  13. #13
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,824
    You cannot directly open 97 versions with 365, whatever that would be (likely 2016 or later) so I doubt you can do it programmatically either. If you have a version between 2000 and (I think) 2013 you should backup then convert these files before you can't open them at all.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 3
    Last Post: 02-28-2017, 03:18 PM
  2. Open older version of database
    By NISMOJim in forum Access
    Replies: 3
    Last Post: 05-30-2015, 03:23 PM
  3. Command Buttons on older version of Access
    By Ceadmo in forum Access
    Replies: 7
    Last Post: 05-03-2015, 01:47 PM
  4. Older version Access upgrade to Win-7 64
    By SteveACCESS in forum Access
    Replies: 1
    Last Post: 04-02-2012, 05:46 PM
  5. Replies: 5
    Last Post: 10-28-2011, 12:12 PM

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