| :: How to Print a Report and open a Form contained in an Access Database |
Author |
Andrea Tincani |
Language |
VB5, VB6 |
Operating
Systems |
Windows 95, 98 and NT |
| API
Declarations |
Option Explicit
'API Declarations
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal nCmdShow
As Long) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
'API Message Constants
Private Const SW_MAXIMIZE = 3
Private Const SW_NORMAL = 1 |
| Usage |
'add the Microsoft
Access 8.0 Object Library to the project references...Create a Form with three Command
Buttons and enjoy with this code
'Create a new Access Instance
Dim appAccess As New Access.Application
Public Sub MaximizeAccess()
'Maximize
Access Application
Dim hWnd As Long
hWnd = FindWindow("OMain", "Microsoft Access")
If hWnd <> 0 Then
ShowWindow hWnd, SW_NORMAL
ShowWindow hWnd, SW_MAXIMIZE
End If
End Sub
'Open an Access Form
Private Sub Command1_Click()
appAccess.DoCmd.OpenForm "Categories", acNormal, , , ,
acDialog
End Sub
'Print an Access Report
Private Sub Command2_Click()
appAccess.DoCmd.OpenReport "Catalog", acViewNormal
End Sub
Private Sub Command3_Click()
MaximizeAccess
End Sub
'Open a Database
Private Sub Form_Load()
appAccess.OpenCurrentDatabase "C:\Program Files\Microsoft Visual
Studio\VB98\nwind.mdb", True
End Sub
'Close the database and the
Access Instance
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
appAccess.CloseCurrentDatabase
appAccess.DoCmd.Quit acQuitSaveNone
End Sub |
|
 |
|
 |