Google Answers Logo
View Question
 
Q: Open access form using VB6 ( No Answer,   7 Comments )
Question  
Subject: Open access form using VB6
Category: Computers > Programming
Asked by: jstm-ga
List Price: $10.00
Posted: 03 Mar 2005 21:10 PST
Expires: 02 Apr 2005 21:10 PST
Question ID: 484441
I need to know how to open a access form with a click of button from
my VB6 application. I am using Access version 2003.

I need very easy to understand code as I am new at programming. Please
include special note such as references, components, etc.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Open access form using VB6
From: willcodeforfood-ga on 03 Mar 2005 22:11 PST
 
Draw a button on your VB 6 form and then double-click on it.  This
will open the code editor for VB, create a Sub that is attached to the
button's click event and put the cursor on the first line of the
[empty] Sub.

Type one command in the Sub so that it looks something like this:

Private Sub Command1_Click()
    Shell ("C:\\Program Files\\Microsoft Office\\Office\\MSACCESS.EXE
""C:\\Documents and Settings\\Username\\My Documents\\db1.mdb""
Macro1")
End Sub

Notice that you need to replace every backslash "\" in your filespecs
with a double-backslash "\\".  Also, notice that 2 sets of
double-quotes are placed on either side of the filename passed as the
parameter to MSACCESS.EXE.  You are telling VB to run a shell command
something like this:

c:\files\msaccess.exe "c:\myfiles\data.mdb" mymacro

    location            location of         macro to
   of MS Access        your database        run at startup

You will need to replace the path I've specified in my command with
the appropriate path on your computer to where MSACCESS.EXE is
located.  Use the built-in Windows search tool if you need to.  Also
substitue the correct location of your Access database.  The command
line I've written will also cause Access to run a macro called
"Macro1" when the database is opened.

Now your button will open your Access database and try to run a Macro
called "Macro1".  Create a new macro in Access, add the "Open Form"
action to the macro, specifying the form you want in the Action
Arguments area along the bottom of the macro design screen.

If needed, practice getting the command right from the DOS command
shell and then paste that command into your Shell() function in VB. 
If you do this, make sure that you make each backslash into a
double-backslash, and each double-quote into a double-double-quote. 
Otherwise VB will not parse your command properly.

 /  -->  //
 "  -->  ""

So my command example:

c:\files\msaccess.exe "c:\myfiles\data.mdb" mymacro

becomes:

c:\\files\\msaccess.exe ""c:\\myfiles\\data.mdb"" mymacro

then inside the VB Shell command becomes:

Shell("c:\\files\\msaccess.exe ""c:\\myfiles\\data.mdb"" mymacro")

Good luck.
Subject: Re: Open access form using VB6
From: jstm-ga on 04 Mar 2005 03:07 PST
 
I tryed this and here is the error I received from Access.

"The command line you used to start Microsoft Office Access contains
an option that Microsoft Office Access doesn't recognize. Exit and
restart Microsoft Office Access using vaild command line options."

Here is my code:

Private Sub Command9_Click()

Shell ("C:\\Program Files\\Microsoft Office\\OFFICE11\\MSACCESS.EXE
""C:\\Production Reporting System\\Production Reporting
System.mdb""Macro1")



End Sub
Subject: Re: Open access form using VB6
From: willcodeforfood-ga on 04 Mar 2005 11:10 PST
 
In your Shell command, put a space before the "M" in Macro1.  It will
then end like:

... System.mdb"" Macro1")
Subject: Re: Open access form using VB6
From: jstm-ga on 04 Mar 2005 16:07 PST
 
Shell ("C:\\Program Files\\Microsoft Office\\OFFICE11\\MSACCESS.EXE
""c:\\temp db\\Production Reporting System.mdb"" runmacro")

I am still getting an error. For some reason it does not like opening a macro?
Subject: Re: Open access form using VB6
From: willcodeforfood-ga on 04 Mar 2005 16:45 PST
 
I assume "runmacro" is the name of your macro.  It should be.  Try
adjusting to this:

Shell ("C:\\Program Files\\Microsoft Office\\OFFICE11\\MSACCESS.EXE
""c:\\temp db\\Production Reporting System.mdb"" /x runmacro")

If this doesn't work, try getting the command to run from the DOS cmd
shell.  Once you get the command to run from the command line, it's a
simple matter to plug it into the Shell command in VB.

Here is a good reference for running Access from the command line:
http://www.vb123.com/workbench/help/commandline.htm
Subject: Re: Open access form using VB6
From: jstm-ga on 04 Mar 2005 17:47 PST
 
YES! This WORKS!!! :)

Could you help me with step by step instructions on creating a bar
chart in visual basic? I have that one posted, but let me know if its
enough money...
Subject: Re: Open access form using VB6
From: willcodeforfood-ga on 05 Mar 2005 08:54 PST
 
I'll take a stab at the chart later this weekend if nobody else chimes
in.  I'm just providing comments so I don't get paid.  Thanks for
offering though.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy