Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2010
    Posts
    88

    Unanswered: How to set Startup Form ... from VBA

    Using Access 2007 ... I know how to set the default (startup) form using the "Access Options" dialog (Current Database tab). Easy. However, I now find myself using VBA to construct a new .accdb file - I am copying tables (+relationships) into it fine, and I can also copy Forms. However, having set up this new .accdb file I now want to set one of the Forms as being the startup form, from my VBA code.

    I have an open access object in my code, and I'm hoping that there is a property somewhere (under CurrentProject perhaps) that I can set, but I've been hunting for a while now and can't find it.

    Can anyone point me towards the right answer?

    TIA

    (Yes, I know I can also copy Macros into my file and I could create one called AutoExec but the reason for not wanting to do this would make this a very long post indeed....)

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try:
    Code:
    Function AddStartupForm()
    
        Dim dbs As DAO.Database
        Dim pty As DAO.Property
        
        Set dbs = CurrentDb
        Set pty = dbs.CreateProperty("StartupForm", dbText, "Form1")
        dbs.Properties.Append pty
        Set pty = Nothing
        Set dbs = Nothing
        
    End Function
    Have a nice day!

  3. #3
    Join Date
    Mar 2010
    Posts
    88
    Yes, that did it (once I'd got rid of the silly mistakes I made first time!)

    Many thanks

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •