{"id":65153,"date":"2025-08-27T12:06:53","date_gmt":"2025-08-27T12:06:53","guid":{"rendered":"http:\/\/www.accessrepairnrecovery.com\/blog\/?p=65153"},"modified":"2025-08-31T07:08:41","modified_gmt":"2025-08-31T07:08:41","slug":"run-vba-code-in-access","status":"publish","type":"post","link":"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access","title":{"rendered":"How to Run VBA Code in Access Without Errors?- (Quick Guide)"},"content":{"rendered":"<div class=\"8e1a49907eb0ebe2b39ac6355e555698\" data-index=\"1\" style=\"float: none; margin:0px 0 0px 0; text-align:center;\">\n<style>\r\n.leaderboard { width: 320px; height: 100px; }\r\n@media(min-width: 500px) { .leaderboard { width: 468px; height: 60px; } }\r\n@media(min-width: 800px) { .leaderboard { width: 728px; height: 90px; } }\r\n<\/style>\r\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-8329139124199643\" crossorigin=\"anonymous\"><\/script>\r\n<ins class=\"adsbygoogle leaderboard\"\r\n     style=\"display:inline-block\"\r\n\t data-full-width-responsive=\"true\"\r\n     data-ad-client=\"ca-pub-8329139124199643\"\r\n     data-ad-slot=\"1972481166\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\n<\/div>\n<p style=\"text-align: justify;\">As we all know, Microsoft Access is a powerful database tool, in which it\u2019s quite easy to create a database with several objects like reports, forms, tables, etc. But when it comes to adding some programming for the simultaneous execution of DB objects or to automate certain processes, then this can be daunting. Running VBA code in Access helps automate such tasks, build custom functions, and manage data efficiently. This guide explains <strong>how to run VBA code in Access<\/strong> step by step.<\/p>\n<p style=\"text-align: justify;\"><!--more--><\/p>\n<div style='margin: 10px 0; clear: both;'><div style='clear: both; border-top: 1px solid #eeeeee; border-bottom: 1px solid #eeeeee; margin: 30px auto; padding: 15px 15px 15px 20px; display: flex; align-items: center; justify-content: space-between;'><div style='margin-bottom: 0; line-height: 1.6; flex-shrink: 1;'><span style='color:#aaa; font-size: 13px;'>Rated <i>Excellent<\/i> on <a rel='nofollow' target='_blank' href='https:\/\/www.trustpilot.com\/review\/www.stellarinfo.com'><span style='color: #aaa;'>Trustpilot<\/span><\/a><\/span><br><strong>Free MS Access Database Repair Tool<\/strong><br>Repair corrupt MDB and ACCDB database files and recover deleted database tables, queries, indexes and records easily. Try Now!<br><div style='margin-top: 5px;'><a style='background: #b10923; border-radius: 25px; color: #ffffff; cursor: pointer; display: inline-block; font-size: 16px; font-weight: 500; padding: 0 16px; height: 40px; line-height: 40px; vertical-align: middle; white-space: nowrap; text-decoration: none; border: none;' href='https:\/\/www.accessrepairnrecovery.com\/blog\/get-access-file-repair-tool' target='_blank'><span style='color: #ffffff;'><i class='fas fa-arrow-alt-circle-down'><\/i><\/span> Download<\/a><br><span style='font-style: italic; display: block; font-size: 10px; margin-top: 10px;'>By clicking the button above and installing Stellar Repair for Access (14.8 MB), I acknowledge that I have read and agree to the <a href='https:\/\/www.accessrepairnrecovery.com\/eula.php' target='_blank'>End User License Agreement<\/a> and <a href='https:\/\/www.accessrepairnrecovery.com\/privacy-policy.php' target='_blank'>Privacy Policy<\/a> of this site.<\/span><\/div><\/div><\/div><\/div>\n<h2 style=\"text-align: left;\"><strong>Understand MS Access VBA Code With Example:<\/strong><\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65172\" src=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/isometric-education-illustration_23-2148074450.jpg\" alt=\"Understand MS Access VBA Code With Example\" width=\"338\" height=\"284\" srcset=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/isometric-education-illustration_23-2148074450.jpg 338w, https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/isometric-education-illustration_23-2148074450-300x252.jpg 300w\" sizes=\"auto, (max-width: 338px) 100vw, 338px\" \/><\/p>\n<p style=\"text-align: justify;\">In MS Access, programming is the way by which we can add functionality to our database. Basically, it is done in two ways:<\/p>\n<ul style=\"text-align: justify;\">\n<li>by using Access macros<\/li>\n<li>or Visual Basic for Applications (VBA) code<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">Suppose, for instance, you have made a report or form in your Access database. Now you want to add a command button to that form. So that when it is clicked, it will automatically open the report.<\/p>\n<p style=\"text-align: justify;\">In that case, programming is used to create a macro or VBA procedure for setting the command button <strong>OnClick<\/strong> event property.\u00a0 When you click the command button, the macro and procedure will automatically run in the background. Thus, clicking on the form\u2019s command button will open the report.<\/p>\n<p style=\"text-align: justify;\">So, all in all, you can say, <strong>VBA code in Access<\/strong> lets you add automation and several functionalities to your Access database application.<\/p>\n<h2 style=\"text-align: left;\">What Is The VBA Editor?<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65170\" src=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/images.jpg\" alt=\"What Is The VBA Editor\" width=\"456\" height=\"236\" \/><\/p>\n<ul>\n<li style=\"text-align: justify;\">Well, for programming in Access, we use the VBA editor. To start the VBA editor, first go to the Create option.<\/li>\n<li style=\"text-align: justify;\">After then tap to the module button in your database window.<\/li>\n<li style=\"text-align: justify;\">This will open the VBA editor.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">As you can see in the figure, this VBA editor has several parts. So, let\u2019s discuss each section in detail:<\/p>\n<ul style=\"text-align: justify;\">\n<li style=\"text-align: left;\">The upper left corner is called <strong>Project Window<\/strong>. This contains a list of all the elements and modules defined in the database.<\/li>\n<li style=\"text-align: left;\">Below the project window, there is a properties window. In this, you can specify different attributes for the objects you have used in the project window.<\/li>\n<li style=\"text-align: left;\">At the bottom, there is an immediate window. Here you can test your procedure parts meanwhile the development. Other than it can also be used for getting immediate results of various commands. The immediate window is very useful during testing and debugging procedures.<\/li>\n<\/ul>\n<h2 style=\"text-align: left;\"><strong>Benefits Of Using VBA Code In Access:<\/strong><\/h2>\n<p style=\"text-align: justify;\">Here are some basic reasons why you need to use <a href=\"https:\/\/www.accessrepairnrecovery.com\/blog\/microsoft-access-vba-code\"><strong>MS Access VBA code<\/strong><\/a> areas as follows.<\/p>\n<ol style=\"text-align: justify;\">\n<li>Manage smaller re-usable procedures (globally)<\/li>\n<li>Create your own defined functions<\/li>\n<li>in memory hold variables (globally)<\/li>\n<li>Attach code to an event i.e. a button on a form<\/li>\n<li>Manage more powerful procedures that an Access macro lacks<\/li>\n<li>Easily wind up with other applications and platforms<\/li>\n<li>smartly handle <a href=\"https:\/\/www.accessrepairnrecovery.com\/blog\/ms-access-runtime-errors\"><strong>Access runtime errors<\/strong><\/a><\/li>\n<\/ol>\n<p style=\"text-align: justify;\">To learn Access VBA Code, you don\u2019t need to be a programmer. The important factor in successfully programming with Access VBA is how well you know the structure of MS Access, often called tables, queries, forms, reports, and macros.<em>\u00a0<\/em>It\u2019s a very powerful features of Access to identify where VBA must overcome and improve on functionality.<\/p>\n<h2 style=\"text-align: left;\"><strong>How To Run VBA Code In MS Access?<\/strong><\/h2>\n<h3 style=\"text-align: left;\"><strong>VBA Code To Run A Query In MS Access<\/strong><\/h3>\n<p style=\"text-align: justify;\">Looking for the VBA code to run a query in MS Access? If so, then check out the complete steps to accomplish this task.<\/p>\n<p style=\"text-align: justify;\">You can use the VBA syntax to run a query in MS Access.<\/p>\n<p style=\"text-align: justify;\"><em><strong>DoCmd.OpenQuery &#8220;Query Name&#8221;<\/strong><\/em><\/p>\n<p style=\"text-align: justify;\">Keep it in mind that \u201cquery name\u201d must not be kept within the brackets \u201c[]\u201d.<\/p>\n<h4 style=\"text-align: justify;\"><strong>Steps To Create A VBA To Run A Query In MS Access<\/strong><\/h4>\n<p style=\"text-align: justify;\">Suppose you have an Access database which contains a query named \u201cmax_sales\u201d.<\/p>\n<p style=\"text-align: justify;\">So, here are the complete steps that you need to follow to create a VBA to execute the \u201cmax_sales\u201d query:<\/p>\n<h5 style=\"text-align: justify;\"><strong>Step 1: Add an Access Form<\/strong><\/h5>\n<p style=\"text-align: justify;\">First of all, open your MS access application, after then add an Access Form.<\/p>\n<p style=\"text-align: justify;\">To add a form, you have to go to the <strong>create<\/strong> tab, after then tap on the form icon presented over the MS Access Ribbon:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65260\" src=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-1.png\" alt=\"VBA Code To Run Query In MS Access---1\" width=\"590\" height=\"311\" srcset=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-1.png 590w, https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-1-300x158.png 300w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/p>\n<h5 style=\"text-align: justify;\"><strong>Step 2: Place a Button<\/strong><\/h5>\n<p style=\"text-align: justify;\">In next step, you need to put a button on the Form. For this task, make a click on the <strong>\u2018button icon\u2019<\/strong> present on the <strong>Access Ribbon<\/strong>. After that position that button on your form.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65261\" src=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-2.png\" alt=\"VBA Code To Run Query In MS Access---2\" width=\"681\" height=\"418\" srcset=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-2.png 681w, https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-2-300x184.png 300w\" sizes=\"auto, (max-width: 681px) 100vw, 681px\" \/><\/p>\n<p style=\"text-align: justify;\">You will notice that after placing button on Access form, <em><strong>Command Button Wizard<\/strong><\/em><em>\u00a0<\/em>will appear on your screen. If you don\u2019t need this <strong>Command Button Wizard <\/strong>then you can press the <strong>cancel <\/strong>button.<\/p>\n<h5 style=\"text-align: justify;\"><strong>Step 3: Open the VBA Screen<\/strong><\/h5>\n<p style=\"text-align: justify;\">For writing down the VBA code for the button, you need to open the VBA editor screen. Make a right-tap on the button and then choose the \u2018<strong>Build Event\u2026<\/strong>\u2018option.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65262\" src=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-3.png\" alt=\"VBA Code To Run Query In MS Access---3\" width=\"431\" height=\"256\" srcset=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-3.png 431w, https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-3-300x178.png 300w\" sizes=\"auto, (max-width: 431px) 100vw, 431px\" \/><\/p>\n<p style=\"text-align: justify;\">After then choose the\u00a0<strong>Code Builder<\/strong>\u00a0option, and tap to the <strong>OK<\/strong> option:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65263\" src=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-4.png\" alt=\"VBA Code To Run Query In MS Access---4\" width=\"231\" height=\"285\" \/><\/p>\n<h5 style=\"text-align: justify;\"><strong>Step 4: Write the VBA to Run the Query<\/strong><\/h5>\n<p style=\"text-align: justify;\">It\u2019s time to write the VBA code to run the query.<\/p>\n<p style=\"text-align: justify;\">Check out the complete VBA code as shown in example below (where \u201cmax_sales\u201d \u00a0is the query\u2019s name):<\/p>\n<blockquote>\n<p style=\"text-align: justify;\"><em>Private Sub Command0_Click()\u00a0<\/em><\/p>\n<p style=\"text-align: justify;\"><em>DoCmd.OpenQuery &#8220;max_sales&#8221;\u00a0<\/em><\/p>\n<p style=\"text-align: justify;\"><em>End Sub<\/em><\/p>\n<\/blockquote>\n<p style=\"text-align: justify;\">This is how VBA will appear in Access:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65264\" src=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-5.png\" alt=\"VBA Code To Run Query In MS Access---5\" width=\"425\" height=\"204\" srcset=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-5.png 425w, https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-5-300x144.png 300w\" sizes=\"auto, (max-width: 425px) 100vw, 425px\" \/><\/p>\n<h5 style=\"text-align: justify;\"><strong>Step 5: View the Results<\/strong><\/h5>\n<p style=\"text-align: justify;\">After writing off this VBA code, its time save your work. \u00a0Now get back to your Access form and shift to the form view.<\/p>\n<p style=\"text-align: justify;\">For easy switching to form view, make a click on the <strong>view icon<\/strong> present under the <strong>design tab. <\/strong>Now, from the drop-down list, choose the <strong>form view.<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65265\" src=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-6.png\" alt=\"VBA Code To Run Query In MS Access---6\" width=\"556\" height=\"380\" srcset=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-6.png 556w, https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-6-300x205.png 300w\" sizes=\"auto, (max-width: 556px) 100vw, 556px\" \/><\/p>\n<p style=\"text-align: justify;\">At last make a tap the button to run \u201cmax_sales\u201d query.\u00a0 Now you can <strong>run a query using VBA code<\/strong> just by simply tapping to the button.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65266\" src=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-7.png\" alt=\"VBA Code To Run Query In MS Access---7\" width=\"309\" height=\"204\" srcset=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-7.png 309w, https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/VBA-Code-To-Run-Query-In-MS-Access-7-300x198.png 300w\" sizes=\"auto, (max-width: 309px) 100vw, 309px\" \/><\/p>\n<h3 style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><strong>VBA Code To Run Report In Access<\/strong><\/span><\/h3>\n<p style=\"text-align: justify;\"><strong>DoCmd.OpenReport method <\/strong>is used for opening report. You can use this<strong> DoCmd.OpenReport method <\/strong>to open the report in <strong>design view, Print Report, View Report, Print Preview, Layout View<\/strong>.<\/p>\n<p style=\"text-align: justify;\">Here is the syntax that you have to use:<\/p>\n<blockquote>\n<p style=\"text-align: justify;\"><em><strong>DoCmd.OpenReport (ReportName, View, Filter, WhereCondition, DataMode, WindowMode, OpenArgs)<\/strong><\/em><\/p>\n<\/blockquote>\n<h5 style=\"text-align: justify;\"><strong>Description of the above syntax:<\/strong><\/h5>\n<p style=\"text-align: justify;\">&#8211;\u00a0<strong>ReportName<\/strong>:<\/p>\n<p style=\"text-align: justify;\">It indicates the report name in current database.it needs argument and it should be written within the double quotes.<\/p>\n<p style=\"text-align: justify;\">&#8211;\u00a0<strong>View<\/strong>:<\/p>\n<p style=\"text-align: justify;\">Some common types of report&#8217;s view such as acViewNormal, acViewPreview, acViewLayout, acViewDesign and so on.<\/p>\n<p style=\"text-align: justify;\">You can select any one of these types for specifying your report when it gets open.<\/p>\n<p style=\"text-align: justify;\">&#8211;\u00a0<strong>Filter<\/strong>:<\/p>\n<p style=\"text-align: justify;\">It is a query name which present in the current database. so, set it between double quotes.<\/p>\n<p style=\"text-align: justify;\">&#8211;\u00a0<strong>WhereCondition<\/strong>:<\/p>\n<p style=\"text-align: justify;\">In this place SQL clause is used without the word WHERE. So, you need to keep it in between double quotes.<\/p>\n<p style=\"text-align: justify;\">&#8211;\u00a0<strong>DataMode<\/strong>:\u00a0\u200b<\/p>\n<p style=\"text-align: justify;\">in this argument you have to specify data entry mode for your report. well the mode can be either the editing mode, or just the read mode.<\/p>\n<p style=\"text-align: justify;\">&#8211;<strong>\u00a0WindowMode<\/strong>:<\/p>\n<p style=\"text-align: justify;\">When a report gets open, specify the window mode.<\/p>\n<p style=\"text-align: justify;\">Besides that, you can open the report in following mode: acDialog, acHidden, acIcon or acWindowNormal.<\/p>\n<p style=\"text-align: justify;\">\u00a0\u00a0\u00a0\u00a0 +\u00a0<strong>acDialog<\/strong>: The open report is fixed and can\u2019t be move.<\/p>\n<p style=\"text-align: justify;\">\u00a0\u00a0\u00a0\u00a0 +\u00a0<strong>acHidden<\/strong>: in this mode, the open report is hidden.<\/p>\n<p style=\"text-align: justify;\">\u00a0\u00a0\u00a0\u00a0 +\u00a0<strong>acIcon<\/strong>: The opened report appears like an icon.<\/p>\n<p style=\"text-align: justify;\">\u00a0\u00a0\u00a0\u00a0 +\u00a0<strong>acWindowNormal<\/strong>: in this mode, the open report appears as the view report.<\/p>\n<p style=\"text-align: justify;\">&#8211;\u00a0<strong>OpenArgs<\/strong>:<\/p>\n<p style=\"text-align: justify;\">Using this argument, you need to specify the record when report gets open.<\/p>\n<p style=\"text-align: justify;\">And you need to keep it in between the double quotes.<\/p>\n<p style=\"text-align: justify;\"><strong>Remark:\u00a0<\/strong><\/p>\n<p style=\"text-align: justify;\">All the arguments mentioned above in DoCmd.OpenReport syntax are optional excluding ReportName argument.<\/p>\n<p style=\"text-align: justify;\">suppose you have a form like this:<\/p>\n<p style=\"text-align: justify;\">if you are opening a form for first time, the current record is Cate001. To print this category, tap to the <strong>Print Report<\/strong> button. It will display the report Cate001 along with the products it contained.<\/p>\n<p style=\"text-align: justify;\">For printing off the Cate002 record, you need to firstly switch to this record. After then tap to the <strong>Print Report<\/strong> button.<\/p>\n<p style=\"text-align: justify;\">But if you need to print Cate003, Cate004, Cate005, and so on. Then you have to create master detail report as shown in figure:<\/p>\n<p style=\"text-align: justify;\">After then you need to apply the VBA code in the CmdPrint_Click event procedure, like this:<\/p>\n<blockquote>\n<p style=\"text-align: justify;\"><em>Private Sub\u00a0CmdPrint_Click()<\/em><br \/>\n<em>DoCmd.OpenReport &#8220;RptProductByCategory&#8221; _<\/em><br \/>\n<em>, acViewReport, , &#8220;CategoryID='&#8221; &amp; txtCategoryID &amp; &#8220;&#8216;&#8221;<\/em><br \/>\n<em>End Sub<\/em><\/p>\n<\/blockquote>\n<p style=\"text-align: justify;\">For Calling the Report from VBA, try the following VBA code:<\/p>\n<blockquote>\n<p style=\"text-align: justify;\"><em>Sub runReport()<\/em><\/p>\n<p style=\"text-align: justify;\"><em>\u00a0\u00a0\u00a0 Dim con As ADODB.Connection<\/em><\/p>\n<p style=\"text-align: justify;\"><em>\u00a0\u00a0\u00a0\u00a0 Set con = New ADODB.Connection<\/em><\/p>\n<p style=\"text-align: justify;\"><em>\u00a0\u00a0\u00a0\u00a0 con.Open &#8220;Provider=Microsoft.Jet.OLEDB.4.0;&#8221; &amp; _<\/em><\/p>\n<p style=\"text-align: justify;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8220;Data Source=C:\\mydb.mdb;&#8221;<\/em><\/p>\n<p style=\"text-align: justify;\"><em>\u00a0\u00a0\u00a0\u00a0 DoCmd.OpenReport &#8220;rptCustomer&#8221;, acViewPreview<\/em><\/p>\n<p style=\"text-align: justify;\"><em>End Sub<\/em><\/p>\n<\/blockquote>\n<h3 style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><strong>MS Access VBA Code To Open Another Database<\/strong><\/span><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65160\" src=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/it-specialists-upgrading-operating-system-illustration_1262-18941.jpg\" alt=\"How To Connect Access And Excel Through VBA\" width=\"564\" height=\"424\" srcset=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/it-specialists-upgrading-operating-system-illustration_1262-18941.jpg 626w, https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/it-specialists-upgrading-operating-system-illustration_1262-18941-300x226.jpg 300w, https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/it-specialists-upgrading-operating-system-illustration_1262-18941-320x240.jpg 320w\" sizes=\"auto, (max-width: 564px) 100vw, 564px\" \/><\/p>\n<p style=\"text-align: justify;\">Do you know you can launch another database from being within the current database? Well this can be done in three different ways. So just check it out\u2026!<\/p>\n<ul style=\"text-align: justify;\">\n<li>FollowHyperlink Method<\/li>\n<li>Shell<\/li>\n<li>Access Automation<\/li>\n<\/ul>\n<h4 style=\"text-align: justify;\"><strong>Method 1: FollowHyperlink Method<\/strong><\/h4>\n<p style=\"text-align: justify;\">FollowHyperlink is a native method of Access database and user can open any file type using the default program associated with it.<\/p>\n<p style=\"text-align: justify;\">As, it is a native command of MS Access, so you are not allowed to use for other programs like Word, Excel, PowerPoint \u2026).<\/p>\n<blockquote><p><em><strong>Public<\/strong> <strong>Function<\/strong> OpenDb3(sDb <strong>As<\/strong> <strong>String<\/strong>)\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0<strong>On<\/strong> <strong>Error<\/strong> <strong>GoTo<\/strong> Error_Handler\u00a0\u00a0\u00a0\u00a0 <\/em><\/p>\n<p><em>Application.FollowHyperlink sDb\u00a0Error_Handler_Exit:\u00a0<\/em><\/p>\n<p><em>\u00a0 \u00a0<strong>On<\/strong> <strong>Error<\/strong> <strong>Resume<\/strong> <strong>Next<\/strong>\u00a0\u00a0<\/em><\/p>\n<p><em> \u00a0<strong>Exit<\/strong> <strong>Function<\/strong>\u00a0Error_Handler:\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>MsgBox &#8220;The following error has occurred&#8221; &amp; vbCrLf &amp; vbCrLf &amp; _\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0&#8220;Error Number: &#8221; &amp; Err.Number &amp; vbCrLf &amp; _\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0&#8220;Error Source: OpenDb3&#8221; &amp; vbCrLf &amp; _\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0 \u00a0&#8220;Error Description: &#8221; &amp; Err.Description &amp; _\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0 Switch(Erl = 0, &#8220;&#8221;, Erl &lt;&gt; 0, vbCrLf &amp; &#8220;Line No: &#8221; &amp; Erl) _\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0 , vbOKOnly + vbCritical, &#8220;An Error has Occurred!&#8221;\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0<strong>Resume<\/strong> Error_Handler_Exit<\/em><\/p>\n<p><em><strong>End<\/strong> <strong>Function<\/strong><\/em><\/p><\/blockquote>\n<h4 style=\"text-align: justify;\"><strong>Method 2:\u00a0 <\/strong><strong style=\"text-align: justify;\">Shell<\/strong><\/h4>\n<p style=\"text-align: justify;\">Shell is universal command which can be used to perform many task. Apart from having long list of capabilities, it is also used to start programs and for opening files. You have to assign the .exe file after then what so ever command line switches recognizes by each of the individual exe file.<\/p>\n<p style=\"text-align: justify;\">Since MS Office is well registered one and it\u2019s a part of path variable. So, you don\u2019t need to give the path for msaccess.exe file just provide the file or path to get open.<\/p>\n<p style=\"text-align: justify;\">If you are having multiple MS Office version installed on your PC and you need to use any specific one. then in that case you need to include the path\/file of the <strong>executable Access database.<\/strong><\/p>\n<blockquote><p><em><strong>Public<\/strong> <strong>Function<\/strong> OpenDb2(sDb <strong>As<\/strong> <strong>String<\/strong>)<\/em><\/p>\n<p><em>\u00a0\u00a0 \u00a0<strong>On<\/strong> <strong>Error<\/strong> <strong>GoTo<\/strong> Error_Handler<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0 Shell &#8220;cmd \/c &#8221; &amp; Chr(34) &amp; sDb &amp; Chr(34), vbHide\u00a0Error_Handler_Exit:\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0<strong>On<\/strong> <strong>Error<\/strong> <strong>Resume<\/strong> <strong>Next<\/strong>\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0<strong>Exit<\/strong> <strong>Function<\/strong>\u00a0Error_Handler:\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0 MsgBox &#8220;The following error has occurred&#8221; &amp; vbCrLf &amp; vbCrLf &amp; _\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0&#8220;Error Number: &#8221; &amp; Err.Number &amp; vbCrLf &amp; _\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0 \u00a0&#8220;Error Source: OpenDb2&#8221; &amp; vbCrLf &amp; _\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0 \u00a0&#8220;Error Description: &#8221; &amp; Err.Description &amp; _\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0 Switch(Erl = 0, &#8220;&#8221;, Erl &lt;&gt; 0, vbCrLf &amp; &#8220;Line No: &#8221; &amp; Erl) _<\/em><\/p>\n<p><em>\u00a0 \u00a0 , vbOKOnly + vbCritical, &#8220;An Error has Occurred!&#8221;\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0<strong>Resume<\/strong> Error_Handler_Exit<\/em><\/p>\n<p><em><strong>End<\/strong> <strong>Function<\/strong><\/em><\/p><\/blockquote>\n<h4 style=\"text-align: justify;\"><strong>Method 3: <\/strong><strong style=\"text-align: justify;\">Access Automation<\/strong><\/h4>\n<p style=\"text-align: justify;\">Access Automation is the superb option to perform any action you want and obviously opening database also.<\/p>\n<blockquote><p><em><strong>Public<\/strong> <strong>Function<\/strong> OpenDb(sDb <strong>As<\/strong> <strong>String<\/strong>)\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0<strong>On<\/strong> <strong>Error<\/strong> <strong>GoTo<\/strong> Error_Handler\u00a0 \u00a0<\/em><\/p>\n<p><em>&#8216;Early binding\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0&#8216;Use the following line if being used in Access or using Access reference\u00a0<\/em><\/p>\n<p><em>\u00a0 \u00a0&#8216;\u00a0\u00a0 provides intellisense!\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0<strong>Dim<\/strong> oAccess\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0<strong>As<\/strong> Access.Application \u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0&#8216;Late binding\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0&#8216;Use the following line if being used outside of Access without an Access reference&#8217;\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>Dim oAccess\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0As Object\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0 \u00a0<strong>Set<\/strong> oAccess = <strong>CreateObject<\/strong>(&#8220;Access.Application&#8221;)\u00a0\u00a0 \u00a0&#8216;Create a new Access instance\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0<strong>With<\/strong> oAccess\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0 .OpenCurrentDatabase sDb\u00a0\u00a0 \u00a0&#8216;Open the specified db\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0 .Visible = <strong>True<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0&#8216;Ensure it is visible to the end-user\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>.UserControl = <strong>True<\/strong>&#8216;\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0 .DoCmd.OpenForm &#8220;YourFormName&#8221;\u00a0\u00a0\u00a0&#8216;Open a form?&#8217;\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0 .DoCmd.RunMacro &#8220;YourMacroName&#8221;\u00a0 &#8216;Run a Macro?\u00a0\u00a0 \u00a0<\/em><\/p>\n<p><em><strong>End<\/strong> <strong>With<\/strong>\u00a0<\/em><\/p>\n<p><em>Error_Handler_Exit:\u00a0<\/em><\/p>\n<p><em>\u00a0<strong>On<\/strong> <strong>Error<\/strong> <strong>Resume<\/strong> <strong>Next<\/strong>\u00a0<\/em><\/p>\n<p><em>\u00a0 \u00a0<strong>If<\/strong> <strong>Not<\/strong> oAccess <strong>Is<\/strong> <strong>Nothing<\/strong> <strong>Then<\/strong> <strong>Set<\/strong> oAccess = <strong>Nothing<\/strong>\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0<strong>Exit<\/strong> <strong>Function<\/strong>\u00a0<\/em><\/p>\n<p><em>Error_Handler:\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0 MsgBox &#8220;The following error has occurred&#8221; &amp; vbCrLf &amp; vbCrLf &amp; _\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0 \u00a0&#8220;Error Number: &#8221; &amp; Err.Number &amp; vbCrLf &amp; _\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0 \u00a0&#8220;Error Source: OpenDb&#8221; &amp; vbCrLf &amp; _\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0 \u00a0&#8220;Error Description: &#8221; &amp; Err.Description &amp; _\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0 Switch(Erl = 0, &#8220;&#8221;, Erl &lt;&gt; 0, vbCrLf &amp; &#8220;Line No: &#8221; &amp; Erl) _\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0 , vbOKOnly + vbCritical, &#8220;An Error has Occurred!&#8221;\u00a0\u00a0<\/em><\/p>\n<p><em>\u00a0<strong>Resume<\/strong> Error_Handler_Exit<\/em><\/p>\n<p><em><strong>End<\/strong> <strong>Function<\/strong><\/em><\/p><\/blockquote>\n<h2 style=\"text-align: left;\"><strong style=\"text-align: center;\">Automate Access From Other MS Office Application Using VBA<\/strong><\/h2>\n<h4>VBA Access Object Library<\/h4>\n<p style=\"text-align: justify;\">In order to automate Access from other MS office application using VBA. Or if you require to use objects of other applications like Microsoft Excel or Word in Access. To make such tasks possible, add object library references. Basically, there are two options to perform this task:<\/p>\n<ol style=\"text-align: justify;\">\n<li>Early binding<\/li>\n<li>Late binding<\/li>\n<\/ol>\n<p style=\"text-align: justify;\">First method, is used to add reference to <strong>Microsoft<\/strong>\u00a0<strong>Access<\/strong>\u00a0<strong>Object Library, <\/strong>just\u00a0before execution. It executes faster, and you will get easy access to the VBA editor <strong>intellisense.<\/strong><\/p>\n<p style=\"text-align: justify;\">Apart from this there is chances to have a <strong>compatibility<\/strong>\u00a0issues while running a PC program with different version of installed library.<\/p>\n<h4 style=\"text-align: justify;\">Method 1: <strong>Early Binding<\/strong><\/h4>\n<p style=\"text-align: justify;\">In this specific method you need to add reference to <strong>Microsoft<\/strong>\u00a0<strong>Access<\/strong>\u00a0<strong>Object. <\/strong><\/p>\n<ol style=\"text-align: justify;\">\n<li>Go to the VBA editor window, and tap to the \u201cTools\u201d button present in menu bar.<\/li>\n<li>Now from the drop-down list, choose the \u201cReferences\u201d option.<\/li>\n<li>Afterward, the \u201cReferences \u2013 Project 1\u201d dialog box will appear.<\/li>\n<li>In this dialog box, you can drag the scroll bar until you fetch what you want like \u201cMicrosoft Access14.0 Object Library\u201d.<\/li>\n<li>Now put a mark in the checkbox present in front of this object.<\/li>\n<li>At last, tap on the \u201cOK\u201d option.<\/li>\n<li>After this step, you have successfully added the Access object library reference.<\/li>\n<\/ol>\n<p style=\"text-align: justify;\">Well you can make use of the above steps to add object libraries as per your requirement.<\/p>\n<p style=\"text-align: justify;\"><strong>Note:<\/strong><\/p>\n<p style=\"text-align: justify;\">Use the following code for defining an <strong>Access.Application object<\/strong> and initiating it:<\/p>\n<blockquote><p><em>Dim\u00a0objAccess\u00a0As\u00a0Access.Application<\/em><br \/>\n<em>set objAccess = new Access.Application<\/em><\/p><\/blockquote>\n<h4 style=\"text-align: justify;\">Method 2: Late Binding<\/h4>\n<p style=\"text-align: justify;\">This method doesn\u2019t require any additional reference to the object library. The Access Application object is declared as a normal <strong>object<\/strong>\u00a0and initiated as shown here:<\/p>\n<blockquote><p><em>Dim\u00a0objAccess\u00a0As\u00a0Object<\/em><br \/>\n<em>Set\u00a0objAccess = CreateObject(&#8220;Access.Application&#8221;)<\/em><\/p><\/blockquote>\n<h2 style=\"text-align: left;\"><strong>How To Connect Access And Excel Through VBA?<\/strong><\/h2>\n<p style=\"text-align: justify;\"><em>In this section, we will discuss about how to connect Access database with the Excel by making use of the VBA code.<\/em><\/p>\n<p style=\"text-align: justify;\">Here is how you can setup a connection with Access database. Connection string used for access 2003<em>(*.mdb) and Access 2007\/2010 (*.accdb) is different because both database version has different drivers.<\/em><\/p>\n<p style=\"text-align: justify;\"><em>For Access 2003 Database the Provider is: Provider = Microsoft.Jet.OLEDB.4.0.<\/em><\/p>\n<p style=\"text-align: justify;\"><em>For Access 2007\/2010 the Provider is Provider = Microsoft.ACE.OLEDB.12.0<\/em><\/p>\n<p style=\"text-align: justify;\"><em>Before executing the below mentioned code, you need to add references for ADO DB Connection.<\/em><\/p>\n<p style=\"text-align: justify;\"><em>\u00a0Follow down these steps for Adding Reference:<\/em><\/p>\n<p style=\"text-align: justify;\"><em>How to add References in excel<\/em><\/p>\n<ul style=\"text-align: justify;\">\n<li>Open the VB Editor Screen by pressing Alt+F11<\/li>\n<li>Tools \u2013&gt; References\u2026<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-67986 aligncenter\" src=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2020\/10\/go-to-tools-to-select-references.png\" alt=\"Check for Missing References\" width=\"462\" height=\"171\" \/><\/p>\n<ul style=\"text-align: justify;\">\n<li>In the List of References Available over there, search for the <strong>\u201cMicrosoft ActiveX Data Objects 2.0 Library\u201d<\/strong>. Choose either 2.0 Version or any other reference of a higher version.<\/li>\n<li>Tap to the <strong>OK<\/strong> option.<\/li>\n<\/ul>\n<h4 style=\"text-align: justify;\"><strong>Connection with Access 2003 Database<\/strong><\/h4>\n<blockquote>\n<p style=\"text-align: justify;\"><em>Sub ADO_Conn()\u00a0<\/em><\/p>\n<p style=\"text-align: justify;\"><em>Dim conn As New Connection<\/em><\/p>\n<p style=\"text-align: justify;\"><em>Dim rs As New Recordset\u00a0\u00a0\u00a0\u00a0 <\/em><\/p>\n<p style=\"text-align: justify;\"><em>strcon = &#8220;Provider=Microsoft.Jet.OLEDB.4.0;&#8221; &amp; _\u00a0\u00a0\u00a0<\/em><\/p>\n<p style=\"text-align: justify;\"><em> &#8220;Data Source=E:\\Student.accdb;&#8221; &amp; _\u00a0\u00a0 <\/em><\/p>\n<p style=\"text-align: justify;\"><em>&#8220;User Id=admin;Password=&#8221;\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p style=\"text-align: justify;\"><em> conn.Open (strcon)\u00a0\u00a0\u00a0\u00a0 <\/em><\/p>\n<p style=\"text-align: justify;\"><em>qry = &#8220;SELECT * FROM students&#8221;\u00a0\u00a0<\/em><\/p>\n<p style=\"text-align: justify;\"><em>rs.Open qry, conn, adOpenKeyset\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p style=\"text-align: justify;\"><em> rs.Close\u00a0<\/em><\/p>\n<p style=\"text-align: justify;\"><em>conn.Close\u00a0<\/em><\/p>\n<p style=\"text-align: justify;\"><em>End Sub<\/em><\/p>\n<\/blockquote>\n<h4 style=\"text-align: justify;\" data-fontsize=\"24\" data-lineheight=\"36\"><strong>Connection with Access 2010\/2007 Database<\/strong><\/h4>\n<blockquote>\n<p style=\"text-align: justify;\"><em>Sub ADO_Conn()<\/em><\/p>\n<p style=\"text-align: justify;\"><em>Dim conn As New Connection<\/em><\/p>\n<p style=\"text-align: justify;\"><em>Dim rs As New Recordset\u00a0\u00a0\u00a0\u00a0 <\/em><\/p>\n<p style=\"text-align: justify;\"><em>strcon = &#8220;Provider=Microsoft.ACE.OLEDB.12.0;&#8221; &amp; _\u00a0\u00a0<\/em><\/p>\n<p style=\"text-align: justify;\"><em>\u00a0&#8220;Data Source=E:\\Student.accdb;&#8221; &amp; _\u00a0<\/em><\/p>\n<p style=\"text-align: justify;\"><em>&#8220;User Id=admin;Password=&#8221;\u00a0\u00a0\u00a0\u00a0 conn.Open (strcon)\u00a0\u00a0<\/em><\/p>\n<p style=\"text-align: justify;\"><em>qry = &#8220;SELECT * FROM students&#8221;\u00a0 \u00a0<\/em><\/p>\n<p style=\"text-align: justify;\"><em>rs.Open qry, conn, adOpenKeyset\u00a0\u00a0\u00a0\u00a0<\/em><\/p>\n<p style=\"text-align: justify;\"><em> rs.Close\u00a0\u00a0\u00a0 <\/em><\/p>\n<p style=\"text-align: justify;\"><em>conn.Close<\/em><\/p>\n<p style=\"text-align: justify;\"><em>End Sub<\/em><\/p>\n<\/blockquote>\n<h2 style=\"text-align: left;\"><strong>What Are the Best Practices for Running Access VBA Code?<\/strong><\/h2>\n<p>Here are the best practices for running Access VBA code:<\/p>\n<ol>\n<li>Always back up your crucial database before running new code.<\/li>\n<li>Test your VBA code in a sample database.<\/li>\n<li>Use meaningful names for procedures &amp; modules.<\/li>\n<li>Avoid long events. Break them into smaller functions.<\/li>\n<li>Use error handling with On Error GoTo statements.<\/li>\n<\/ol>\n<h2 style=\"text-align: left;\"><strong>Frequently Asked Questions:<\/strong><\/h2>\n<h4 style=\"text-align: left;\"><strong>How Do I Enable VBA in Access?<\/strong><\/h4>\n<p style=\"text-align: justify;\">To enable VBA in Access, click on the <strong>File<\/strong> &gt;&gt; <strong>Options<\/strong>.\u00a0Under the navigation pane, choose Trust Center.\u00a0In a navigation pane, choose Macro Settings.\u00a0Make sure that Trust access to a VBA project object model is checked.<\/p>\n<h4><strong>How to Run A VBA Code Step by Step?<\/strong><\/h4>\n<p>To run a VBA code step by step, follow the steps below:<\/p>\n<ul>\n<li>Press <strong>F5<\/strong> to run your project.<\/li>\n<li>On a Developer tab, under the Code group, choose Visual Basic.<\/li>\n<li>Go to the <strong>Insert<\/strong> menu, click on the <strong>Module<\/strong>.<\/li>\n<li>Add the code to the new module &amp; press F5.<\/li>\n<li>Verify that a new table was added to the document.<\/li>\n<li>Exit Word without saving your changes.<\/li>\n<\/ul>\n<h4 style=\"text-align: left;\"><strong>How Do I Activate A VBA Code?<\/strong><\/h4>\n<p style=\"text-align: justify;\">You can easily activate a VBA interface by pressing the <strong>ALT + F11<\/strong> keyboard shortcut. Otherwise, you can go to the Developer tab &amp; click on Visual Basic.<\/p>\n<h2 style=\"text-align: left;\"><strong>Final Thoughts<\/strong><\/h2>\n<p style=\"text-align: justify;\"><strong>Running VBA code in MS Access<\/strong> is simple once you know the process. Whether you use the VBA editor, macros, or buttons, you can automate tasks with ease. Start with the small procedures mentioned above in this post and expand your knowledge step by step. With these practices, you will unlock the full power of Microsoft Access.<\/p>\n<div class=\"su-note\"  style=\"border-color:#d9d9d9;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#f3f3f3;border-color:#ffffff;color:#333333;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;\">\n<p><strong>References:<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/support.microsoft.com\/en-au\/office\/runcode-macro-action-e6a62d3f-02c6-4daf-a5f7-402fd600bed4\" target=\"_blank\" rel=\"noopener\">https:\/\/support.microsoft.com\/en-au\/office\/runcode-macro-action-e6a62d3f-02c6-4daf-a5f7-402fd600bed4<\/a><\/li>\n<\/ul>\n<\/div><\/div>\n<div style='margin: 8px 0; clear: both;'><div style='border: 1px solid #e7e7e7; border-radius: 3px; background: #ffffff; color: #000; margin-top: 30px;'><div style='display: inline; background: #fff; padding: 10px; border: 1px solid #e7e7e7; border-bottom-right-radius: 10px; border-top-left-radius: 10px; border-top-right-radius: 10px; margin-left: -1px;'><img src='https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2021\/12\/y-bulb.png' alt='tip' style='vertical-align: middle;' width='30px'><strong style='font-size: 18px; vertical-align: middle;'> Still having issues?<\/strong> Fix them with this Access repair tool: <\/div><div style='padding: 1rem; line-height: 1.6;'><p style='margin: 0; font-size: 17px;'>This software repairs & restores all ACCDB\/MDB objects including tables, reports, queries, records, forms, and indexes along with modules, macros, and other stuffs effectively.<\/p><div><ol style='font-size: 17px;'><li><strong><a href='https:\/\/www.accessrepairnrecovery.com\/blog\/get-access-file-repair-tool' target='_blank'>Download Stellar Repair for Access <\/a><\/strong> rated <i>Great<\/i> on Cnet (<i>download starts on this page<\/i>).<\/li><li>Click <strong>Browse<\/strong> and <strong>Search<\/strong> option to locate corrupt Access database.<\/li><li>Click <strong>Repair<\/strong> button to repair & preview the database objects.<\/li><\/ol><\/div><\/div><\/div><\/div>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>As we all know, Microsoft Access is a powerful database tool, in which it\u2019s quite easy to create a database &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Run VBA Code in Access Without Errors?- (Quick Guide)\" class=\"read-more button\" href=\"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access#more-65153\" aria-label=\"Read more about How to Run VBA Code in Access Without Errors?- (Quick Guide)\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":65169,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[1235,2007],"class_list":["post-65153","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorial","tag-how-to-run-vba-code-in-access","tag-run-microsoft-access-vba","resize-featured-image"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Run VBA Code in Access Without Errors?- (Quick Guide)<\/title>\n<meta name=\"description\" content=\"In this video, you\u2019ll discover a step-by-step guide on how to run VBA code in Access, and speed up your workflow.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Run VBA Code in Access Without Errors?- (Quick Guide)\" \/>\n<meta property=\"og:description\" content=\"In this video, you\u2019ll discover a step-by-step guide on how to run VBA code in Access, and speed up your workflow.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access\" \/>\n<meta property=\"og:site_name\" content=\"MS Access Repair And Recovery Blog\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-27T12:06:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-31T07:08:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/How-To-Run-VBA-Code-In-Access.png\" \/>\n\t<meta property=\"og:image:width\" content=\"626\" \/>\n\t<meta property=\"og:image:height\" content=\"471\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Pearson Willey\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pearson Willey\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access\"},\"author\":{\"name\":\"Pearson Willey\",\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/#\/schema\/person\/9e865a2660c466b5b9c3a485e05f8ecb\"},\"headline\":\"How to Run VBA Code in Access Without Errors?- (Quick Guide)\",\"datePublished\":\"2025-08-27T12:06:53+00:00\",\"dateModified\":\"2025-08-31T07:08:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access\"},\"wordCount\":2835,\"publisher\":{\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/How-To-Run-VBA-Code-In-Access.png\",\"keywords\":[\"how to run vba code in access\",\"run Microsoft Access VBA\"],\"articleSection\":[\"Tutorial\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access\",\"url\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access\",\"name\":\"How to Run VBA Code in Access Without Errors?- (Quick Guide)\",\"isPartOf\":{\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/How-To-Run-VBA-Code-In-Access.png\",\"datePublished\":\"2025-08-27T12:06:53+00:00\",\"dateModified\":\"2025-08-31T07:08:41+00:00\",\"description\":\"In this video, you\u2019ll discover a step-by-step guide on how to run VBA code in Access, and speed up your workflow.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access#primaryimage\",\"url\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/How-To-Run-VBA-Code-In-Access.png\",\"contentUrl\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/How-To-Run-VBA-Code-In-Access.png\",\"width\":626,\"height\":471,\"caption\":\"How To Run VBA Code In Access\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Run VBA Code in Access Without Errors?- (Quick Guide)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/#website\",\"url\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/\",\"name\":\"MS Access Repair And Recovery Blog\",\"description\":\"Your One Stop Destination for MS Access Fixes, Tutorials &amp; More\",\"publisher\":{\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/#organization\",\"name\":\"MS Access Repair And Recovery Blog\",\"url\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2021\/07\/accessrepairnrecovery-com-logo.png\",\"contentUrl\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2021\/07\/accessrepairnrecovery-com-logo.png\",\"width\":350,\"height\":70,\"caption\":\"MS Access Repair And Recovery Blog\"},\"image\":{\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/#\/schema\/person\/9e865a2660c466b5b9c3a485e05f8ecb\",\"name\":\"Pearson Willey\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1e14359741626aa0b5f1415dc1929323c9923a9826470b578bddbc2a39751640?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1e14359741626aa0b5f1415dc1929323c9923a9826470b578bddbc2a39751640?s=96&d=mm&r=g\",\"caption\":\"Pearson Willey\"},\"description\":\"Pearson Willey is a website content writer and long-form content planner. Besides this, he is also an avid reader. Thus he knows very well how to write an engaging content for readers. Writing is like a growing edge for him. He loves exploring his knowledge on MS Access &amp; sharing tech blogs.\",\"url\":\"https:\/\/www.accessrepairnrecovery.com\/blog\/author\/pearson-willey\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Run VBA Code in Access Without Errors?- (Quick Guide)","description":"In this video, you\u2019ll discover a step-by-step guide on how to run VBA code in Access, and speed up your workflow.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access","og_locale":"en_US","og_type":"article","og_title":"How to Run VBA Code in Access Without Errors?- (Quick Guide)","og_description":"In this video, you\u2019ll discover a step-by-step guide on how to run VBA code in Access, and speed up your workflow.","og_url":"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access","og_site_name":"MS Access Repair And Recovery Blog","article_published_time":"2025-08-27T12:06:53+00:00","article_modified_time":"2025-08-31T07:08:41+00:00","og_image":[{"width":626,"height":471,"url":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/How-To-Run-VBA-Code-In-Access.png","type":"image\/png"}],"author":"Pearson Willey","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Pearson Willey","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access#article","isPartOf":{"@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access"},"author":{"name":"Pearson Willey","@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/#\/schema\/person\/9e865a2660c466b5b9c3a485e05f8ecb"},"headline":"How to Run VBA Code in Access Without Errors?- (Quick Guide)","datePublished":"2025-08-27T12:06:53+00:00","dateModified":"2025-08-31T07:08:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access"},"wordCount":2835,"publisher":{"@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access#primaryimage"},"thumbnailUrl":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/How-To-Run-VBA-Code-In-Access.png","keywords":["how to run vba code in access","run Microsoft Access VBA"],"articleSection":["Tutorial"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access","url":"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access","name":"How to Run VBA Code in Access Without Errors?- (Quick Guide)","isPartOf":{"@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access#primaryimage"},"image":{"@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access#primaryimage"},"thumbnailUrl":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/How-To-Run-VBA-Code-In-Access.png","datePublished":"2025-08-27T12:06:53+00:00","dateModified":"2025-08-31T07:08:41+00:00","description":"In this video, you\u2019ll discover a step-by-step guide on how to run VBA code in Access, and speed up your workflow.","breadcrumb":{"@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access#primaryimage","url":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/How-To-Run-VBA-Code-In-Access.png","contentUrl":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2019\/11\/How-To-Run-VBA-Code-In-Access.png","width":626,"height":471,"caption":"How To Run VBA Code In Access"},{"@type":"BreadcrumbList","@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/run-vba-code-in-access#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.accessrepairnrecovery.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Run VBA Code in Access Without Errors?- (Quick Guide)"}]},{"@type":"WebSite","@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/#website","url":"https:\/\/www.accessrepairnrecovery.com\/blog\/","name":"MS Access Repair And Recovery Blog","description":"Your One Stop Destination for MS Access Fixes, Tutorials &amp; More","publisher":{"@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.accessrepairnrecovery.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/#organization","name":"MS Access Repair And Recovery Blog","url":"https:\/\/www.accessrepairnrecovery.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2021\/07\/accessrepairnrecovery-com-logo.png","contentUrl":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-content\/uploads\/2021\/07\/accessrepairnrecovery-com-logo.png","width":350,"height":70,"caption":"MS Access Repair And Recovery Blog"},"image":{"@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/#\/schema\/person\/9e865a2660c466b5b9c3a485e05f8ecb","name":"Pearson Willey","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.accessrepairnrecovery.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1e14359741626aa0b5f1415dc1929323c9923a9826470b578bddbc2a39751640?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1e14359741626aa0b5f1415dc1929323c9923a9826470b578bddbc2a39751640?s=96&d=mm&r=g","caption":"Pearson Willey"},"description":"Pearson Willey is a website content writer and long-form content planner. Besides this, he is also an avid reader. Thus he knows very well how to write an engaging content for readers. Writing is like a growing edge for him. He loves exploring his knowledge on MS Access &amp; sharing tech blogs.","url":"https:\/\/www.accessrepairnrecovery.com\/blog\/author\/pearson-willey"}]}},"_links":{"self":[{"href":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-json\/wp\/v2\/posts\/65153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-json\/wp\/v2\/comments?post=65153"}],"version-history":[{"count":3,"href":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-json\/wp\/v2\/posts\/65153\/revisions"}],"predecessor-version":[{"id":69140,"href":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-json\/wp\/v2\/posts\/65153\/revisions\/69140"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-json\/wp\/v2\/media\/65169"}],"wp:attachment":[{"href":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-json\/wp\/v2\/media?parent=65153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-json\/wp\/v2\/categories?post=65153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.accessrepairnrecovery.com\/blog\/wp-json\/wp\/v2\/tags?post=65153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}