Results 1 to 2 of 2
  1. #1
    tariq1 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    16

    select * using VBA

    Hi,

    This should hopefully be an easy one...

    When running the code below I receive:
    'Run-time error '3024':Could not find file 'database5.mdf''



    I know I am running this in database5, so dont know what the issue is...

    Thank you



    Sub select1()

    Dim dbs As Database
    Dim rst As Recordset
    'Opens database 5
    Set dbs = OpenDatabase("database5.mdf")
    'Selects all records from PALS table
    Set rst = dbs.OpenRecordset("SELECT * from Pals;")
    'Populate the recordset
    rst.MoveLast

    dbs.Close
    End Sub

  2. #2
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    Try this:

    Code:
    Sub select1()
     
    Dim dbs As Database
    Dim rst As Recordset
    'Opens database 5
    Set dbs = currentdb
    'Selects all records from PALS table
    Set rst = dbs.OpenRecordset("SELECT * from Pals;")
    'Populate the recordset
    rst.MoveLast
     
    dbs.Close
    End Sub

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

Similar Threads

  1. Select first row
    By Marko in forum Queries
    Replies: 4
    Last Post: 05-08-2012, 07:37 AM
  2. Select Into VBA
    By snoopy2003 in forum Programming
    Replies: 3
    Last Post: 08-17-2011, 09:20 AM
  3. Replies: 8
    Last Post: 04-21-2011, 05:29 PM
  4. Replies: 4
    Last Post: 03-17-2011, 06:17 AM
  5. Replies: 1
    Last Post: 10-22-2010, 10:11 AM

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