Results 1 to 13 of 13
  1. #1
    Jaap's Avatar
    Jaap is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2017
    Location
    North Holland
    Posts
    49

    Autoexec with macro, or Visual Basic Command

    Hello, I taught myself in the beginning to start a program with an Autoexec Macro, I would like to know what the best method is to start up?


    I myself would like to know if it is also possible via Visual Basic, and how to do this execute, please.

    Click image for larger version. 

Name:	Autostart in Access.jpg 
Views:	46 
Size:	109.3 KB 
ID:	45633

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    You can either use a startup form or an autoexec macro for any code you want to run when your application loads.
    Its largely down to personal preference though I generally use a startup form.

    Two things to bear in mind.
    1. A startup form that is set in Database Options loads before an autoexec macro
    2. If you convert your app into an ACCDE, any code in forms is inaccessible to an end user.
    However, an end user will still be able to modify or disable an autoexec macro
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    Jaap's Avatar
    Jaap is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2017
    Location
    North Holland
    Posts
    49
    Quote Originally Posted by isladogs View Post
    You can either use a startup form or an autoexec macro for any code you want to run when your application loads.
    Its largely down to personal preference though I generally use a startup form.

    Two things to bear in mind.
    1. A startup form that is set in Database Options loads before an autoexec macro
    2. If you convert your app into an ACCDE, any code in forms is inaccessible to an end user.
    However, an end user will still be able to modify or disable an autoexec macro
    Thank you Isladogs, I don't like to convert my program, but if possible I would like to see an example of an 'Startup Form', please?

    Regards, Jaap

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Any form can be opened automatically when your app loads. To do so, click File...Options...Current Database and enter a form name as shown below

    Click image for larger version. 

Name:	Screenshot 2021-07-05 133724.png 
Views:	37 
Size:	60.2 KB 
ID:	45659

    If you want you can add code to the form load event to do whatever else is in your autoexec macro
    Code:
    Private Sub Form_Load()
    
    DoCmd.Hourglass, True
    Application.Echo False
    
    End Sub
    Do make sure you set Echo true and the hourglass false again afterwards!
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    Jaap's Avatar
    Jaap is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2017
    Location
    North Holland
    Posts
    49
    Thank you very much, I am very happy with this information important to me.

    I've one question about the Visual Basic method,
    After Debug - Compile, a message appear, there is something I've done wrong, please?
    Click image for larger version. 

Name:	Debug - Compile July-8-2021.png 
Views:	33 
Size:	194.0 KB 
ID:	45681
    Regards, Jaap
    Attached Thumbnails Attached Thumbnails Debug - Compile July-8-2021.png  

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Remove the .Echo from that line. Your code for that line should be
    Code:
    DoCmd.Hourglass True
    NOTE In my last post, I wrongly included a comma but I'm no longer able to edit that post to correct it
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    Jaap's Avatar
    Jaap is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2017
    Location
    North Holland
    Posts
    49
    Thank you isladogs for helping me, now it's working without a warning. :-)

    Private Sub Form_Load()
    On Error GoTo Fout
    DoCmd.Hourglass True
    Application.Echo False
    Fout:
    Exit Sub
    End Sub

    For me, this Topic is solved.

    Regards, Jaap

  8. #8
    Jaap's Avatar
    Jaap is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2017
    Location
    North Holland
    Posts
    49
    Dear isLadogs,

    I'd like to ask you something, please.

    Click image for larger version. 

Name:	Current Database Feb-26-2023.png 
Views:	19 
Size:	41.7 KB 
ID:	49789

    Today I used your Example and explanation to start an Access program without an Autoexec.bat file

    After making this Settings, the program is starting correctly without a AutoExec file. :-)

    But when I using also this VBA commands in Form SchakelbordF:

    Private Sub Form_Load()
    On Error GoTo Failure
    DoCmd.Hourglass True
    Application.Echo False
    Failure:
    Exit Sub
    End Sub

    The Access program will not start anymore,
    the hourglass keeps spinning?

    It is necessary to use this VBA commands?

    Regards,
    Jaap

    Last edited by Jaap; 02-26-2023 at 07:12 AM. Reason: Deleted wrong image.

  9. #9
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    The hourglass will continue to spin until code is used to set it to false.
    Similarly screen updating will stay disabled until Application Echo is set to true.
    You will see I do both of those in my example

    If that is your entire Form_Load code, it is causing your problem and doing nothing useful. Get rid of it.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  10. #10
    Jaap's Avatar
    Jaap is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2017
    Location
    North Holland
    Posts
    49
    Dear isladogs, thank you for this reply.

    The program works very well with just 'Access Options' and 'Current Database' with the data you sent me.


    I also did not program any VBA data into 'Private Sub Form_Load()'.


    I also deleted all macros, including the AutoExec file.


    I want to ask you if it's good enough now, please?

    Regards,
    Jaap

  11. #11
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Quote Originally Posted by Jaap View Post
    I want to ask you if it's good enough now, please?
    How would I be able to know?
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  12. #12
    Jaap's Avatar
    Jaap is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2017
    Location
    North Holland
    Posts
    49
    The setting of 'Access Options' and 'Current Database' ensures that my computer boots properly to my Switch Form.
    So further safety precautions are not necessary at this point.


    Thanks isLadogs for the cooperation.


    Regards,
    Jaap

  13. #13
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Glad you have a solution that works for your needs
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Visual Basic
    By Darth21 in forum Access
    Replies: 4
    Last Post: 08-11-2014, 06:18 AM
  2. Visual Basic Code for If Else
    By Baldeagle in forum Programming
    Replies: 1
    Last Post: 09-14-2012, 08:46 AM
  3. Visual Basic
    By kwooten in forum Queries
    Replies: 2
    Last Post: 01-25-2012, 08:22 AM
  4. how to use visual basic in access
    By learning_graccess in forum Access
    Replies: 3
    Last Post: 12-05-2011, 03:23 PM
  5. trying to learn visual basic
    By darklite in forum Programming
    Replies: 7
    Last Post: 08-24-2011, 02:18 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