Results 1 to 6 of 6
  1. #1
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116

    Open Database Event in VBA

    I want to create an event that runs when I start up my database. It's basically an append query.

    I read here that I need to create a public function. But I tried that and no go.

    Code:
    Public Function DoSomething()DoCmd.SetWarnings (False)
    DoCmd.OpenQuery "Append"
    End Function
    I did a search on these forums and couldn't find a solution. Any suggestion?

  2. #2
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    564
    don't you need to call if from a macro called "AutoExec"?

    If you want to run an action query, don't do it that way. Instead...

    CurrentDb.Execute "QueryName"

    then you don't need the SetWarnings False and then True at all.

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    Your link provides the solution? What don’t you understand ?

  4. #4
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    I read here that I need to create a public function
    Did you place that function in a standard module? As stated, use that version of Currentdb.Execute or Currentdb.Execute "sql statement in quotes"
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Options for calling procedure when database opens:

    1. AutoExec macro calls VBA Function

    2. Set a form to open automatically when db opens and code in Open event calls Function or Sub.


    Note error in posting your code. Forum merges first two lines into one. No idea why this happens but it is a persistent bug. Can fix it by editing post to break line.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116
    Sorry all. I should have read that article more closely. I was working late last night and missed important details. Marking thread as solved.

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

Similar Threads

  1. Event 1 or Event 2 or Event 3
    By TenOc in forum Programming
    Replies: 2
    Last Post: 03-27-2019, 09:32 AM
  2. Replies: 7
    Last Post: 05-08-2014, 10:34 AM
  3. Replies: 1
    Last Post: 03-29-2014, 07:46 PM
  4. Replies: 3
    Last Post: 05-07-2012, 12:17 PM
  5. Replies: 21
    Last Post: 06-03-2009, 05:54 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