Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am trying to create a button within Excel that will launch MS Access & open
a database. Any ideas? Thanks |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
set AcDb =getobject("C:\temp\MyDB.mdb")
"deeds" wrote: I am trying to create a button within Excel that will launch MS Access & open a database. Any ideas? Thanks |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks....However, I put this code in, run it, and it seems to run but Access
does not open....any thoughts?... "Joel" wrote: set AcDb =getobject("C:\temp\MyDB.mdb") "deeds" wrote: I am trying to create a button within Excel that will launch MS Access & open a database. Any ideas? Thanks |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Add a visible statment. If you check your task manager you probably still
have the database running as a Process. set AcDb =getobject("C:\temp\MyDB.mdb") acdb.Application.Visible = True "deeds" wrote: Thanks....However, I put this code in, run it, and it seems to run but Access does not open....any thoughts?... "Joel" wrote: set AcDb =getobject("C:\temp\MyDB.mdb") "deeds" wrote: I am trying to create a button within Excel that will launch MS Access & open a database. Any ideas? Thanks |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try this:
Option Explicit Option Base 1 Sub Open_Access() Dim accApp As Access.Application Dim accPath As String Dim accDB As String ' ' Define path to your database and database name here ' accPath = "U:\" accDB = "db1.mdb" ' ' Create a new instance of Access and make it visible ' Set accApp = New Access.Application accApp.Visible = True ' ' Open the database ' accApp.OpenCurrentDatabase filepath:=accPath & accDB ' ' Do stuff in the Access database here... ' ' Close the database, exit Access and release the object ' accApp.CloseCurrentDatabase accApp.Quit Set accApp = Nothing ' End Sub -- "deeds" wrote: I am trying to create a button within Excel that will launch MS Access & open a database. Any ideas? Thanks |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Of course, you stick this code in your button's "Click" event!
|
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks!...I hate to say it...but I can't seem to get this to work. Could you
walk through the process of putting this on a button? I did everything you said but still get errors. Thanks "egun" wrote: Of course, you stick this code in your button's "Click" event! |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here are the steps I just went through (starting with a new workbook):
1. Go into Design Mode on whatever worksheet you want to have the button (in my case, Sheet1). The design mode button is in on the Visual Basic toolbar, so if that is not showing, go to View/Toolbars, and select Visual Basic). 2. Show the Control Toolbox using the same method. 3. Add a Command Button to the worksheet by selecting it in the control toolbox and then clicking or click-dragging on the worksheet. By default, mine was named CommandButton1. 4. Right click on the button you just added, and select "View Code". The VB editor opens up, and automatically adds the button's "Click" event. 5. Type in "Open_Access", which will call the subroutine that I gave you earlier. 6. In the VB editor, insert a module by selecting Insert/Module. This will insert a new source code module into the VBA project. 7. Cut and paste the example I gave you into this module, in its entirety. You will need to change the path and the filename to point to an actual Access database on your machine. 8. Make sure that Excel has the references it needs to work with Access by selecting Tools/References... in the Visual Basic editor, and checking the box for "Microsoft Access 11.0 Object Library", or whatever version you are running. 8. Hide the control toolbox and exit Design Mode. 9. Save your workbook! 10. Press the button. It should open up Access and the database you specified. That's the mechanics for hooking up a button to some VBA source. You can now modify the source code so that the button does whatever you want it to do. Hope this helps. |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks....1 more problem...it seems to work...and actually opens Access
however I get the following VBA message...Microsoft Access cannot open the database because it is missing, or opened exclusively by another user"....I do not have the database open when I try this....can't figure out why it won't open it...any ideas? Thanks again "egun" wrote: Here are the steps I just went through (starting with a new workbook): 1. Go into Design Mode on whatever worksheet you want to have the button (in my case, Sheet1). The design mode button is in on the Visual Basic toolbar, so if that is not showing, go to View/Toolbars, and select Visual Basic). 2. Show the Control Toolbox using the same method. 3. Add a Command Button to the worksheet by selecting it in the control toolbox and then clicking or click-dragging on the worksheet. By default, mine was named CommandButton1. 4. Right click on the button you just added, and select "View Code". The VB editor opens up, and automatically adds the button's "Click" event. 5. Type in "Open_Access", which will call the subroutine that I gave you earlier. 6. In the VB editor, insert a module by selecting Insert/Module. This will insert a new source code module into the VBA project. 7. Cut and paste the example I gave you into this module, in its entirety. You will need to change the path and the filename to point to an actual Access database on your machine. 8. Make sure that Excel has the references it needs to work with Access by selecting Tools/References... in the Visual Basic editor, and checking the box for "Microsoft Access 11.0 Object Library", or whatever version you are running. 8. Hide the control toolbox and exit Design Mode. 9. Save your workbook! 10. Press the button. It should open up Access and the database you specified. That's the mechanics for hooking up a button to some VBA source. You can now modify the source code so that the button does whatever you want it to do. Hope this helps. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I launch my macro by button? | Excel Programming | |||
Macro launch - Button vs Manual launch , has different results. | Excel Programming | |||
Launch Excel vba macro from Access? | Excel Programming | |||
button to launch my userform | Excel Programming | |||
Launch Macro in Access via Macro running in Excel??? | Excel Programming |