cherocks
asked on
Modify / Print Access Forms within VB 6 (not VB.net)
Is there a way to connect and make changes to Access reports from VB?
I have a form that is on Access and don't want to go through the pain of converting it to VB, so I figured I could connect and make changes to the Form controls of Access via Visual Basic 6...
So, first is how do I open an mdb file from Access. Next is how do I reference and change various properties of a particular Accessform? And lastly, how do I print it?
Thanks.
<removed email- bingie, ee pe>
I have a form that is on Access and don't want to go through the pain of converting it to VB, so I figured I could connect and make changes to the Form controls of Access via Visual Basic 6...
So, first is how do I open an mdb file from Access. Next is how do I reference and change various properties of a particular Accessform? And lastly, how do I print it?
Thanks.
<removed email- bingie, ee pe>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What error are you getting and where does it highlight in the code?
Bob
Bob
ASKER
Compile error:
Expected function or variable
'OpenCurrentDatabase' is highlighted.
Dave
Expected function or variable
'OpenCurrentDatabase' is highlighted.
Dave
ASKER
What is the exact name of the library (as shown in the References section)? Just want to make sure I select the right things...
Cherocks,
I have something wrong in the code there. I will work on it and post. Sorry for the screw up. Maybe someone else can see it in the meantime.
The Access library is MS Access Object Library 10.0 and the file name is MSACC.OLB - is access 2002 or xp.
The ADO library is MS Active X Data Objects 2.6 library and the file name is msado26.tlb.
Bob
I have something wrong in the code there. I will work on it and post. Sorry for the screw up. Maybe someone else can see it in the meantime.
The Access library is MS Access Object Library 10.0 and the file name is MSACC.OLB - is access 2002 or xp.
The ADO library is MS Active X Data Objects 2.6 library and the file name is msado26.tlb.
Bob
ASKER
I got it to OPEN the database... but the .Forms() command didn't work... it says the form doesn't exist... I typed in the name of the form "Testing" and also tried "Testing.frm" and it didn't like either reference... In addition, the PrintForm command didn't work either...
Option Explicit
'select MS Access 10 and MS ADO 26 libraries from the references list.
Private Sub Form_Load()
Dim objAccess As Access.Application
Set objAccess = New Access.Application
'Open the database and run the macro
With objAccess
.OpenCurrentDatabase "C:\AAA testing\AccessStuff\TestMD B\firstimp ortCompact .mdb"
.Forms("frmCompactRepair.f rm").Contr ols("txt1" ).Top = 200 'change controls on form
End With
'Set app = OpenCurrentDatabase("C:\AA A testing\AccessStuff\TestMD B\firstimp ortCompact .mdb")
End Sub
Option Explicit
'select MS Access 10 and MS ADO 26 libraries from the references list.
Private Sub Form_Load()
Dim objAccess As Access.Application
Set objAccess = New Access.Application
'Open the database and run the macro
With objAccess
.OpenCurrentDatabase "C:\AAA testing\AccessStuff\TestMD
.Forms("frmCompactRepair.f
End With
'Set app = OpenCurrentDatabase("C:\AA
End Sub
ASKER
Ok... I figured it out... Combining some of Bob's code and some that I found online, here's is how you edit / print a form in Access using VB...
Option Explicit
'select MS Access 10 and MS ADO 26 libraries from the references list.
Private Sub Form_Load()
Dim objAccess As Access.Application
Set objAccess = New Access.Application
'Open the database and run the macro
With objAccess
.OpenCurrentDatabase "C:\AAA testing\AccessStuff\TestMD B\firstimp ortCompact .mdb"
.DoCmd.OpenForm ("Testing")
.Forms("Testing").Controls .Item("Lab el999").Ca ption = "Text"
.DoCmd.PrintOut acPrintAll, 1, 1, acHigh, 1, False
.CloseCurrentDatabase
.Quit
End With
End Sub
Option Explicit
'select MS Access 10 and MS ADO 26 libraries from the references list.
Private Sub Form_Load()
Dim objAccess As Access.Application
Set objAccess = New Access.Application
'Open the database and run the macro
With objAccess
.OpenCurrentDatabase "C:\AAA testing\AccessStuff\TestMD
.DoCmd.OpenForm ("Testing")
.Forms("Testing").Controls
.DoCmd.PrintOut acPrintAll, 1, 1, acHigh, 1, False
.CloseCurrentDatabase
.Quit
End With
End Sub
cherocks,
Sorry I abandoned you there. I got caught up in some training and just dropped the ball.
You did good figuring the problem out and should ask that the question be paq'ed and points refunded.
Bob
Sorry I abandoned you there. I got caught up in some training and just dropped the ball.
You did good figuring the problem out and should ask that the question be paq'ed and points refunded.
Bob
ASKER
Bob,
Thanks for the help though... your code gave me a search point to find other code and I combined that with experimentation to find out the answer...
Dave
Thanks for the help though... your code gave me a search point to find other code and I combined that with experimentation to find out the answer...
Dave
ASKER
You stated to have MS Access 10 and MS ADO 26 libraries from the references list....
I have Microsoft Access 9.0 Object Library and Microsoft ADO 2.5 for DLL and Security.... and it isn't working.... Where can I find these libraries? (I've googled 'em and have not been successful)
Dave