A
Asty
I have some problem here. when i run the following program it is asking to
select a
Data source. Possibly it is asking for the driver. : i am just putting my
code here: i am working in visual basic 6. and trying to hide the
application window and show only form using the win 32 api function written
in standard module.
please help me with this . and
please be a little patient for my querie..
Thanks alot..
here is the code:
In form module i have a code like this:
Dim acc As Access.Application
Dim db As DAO.Database
Dim strDbName As String
Const SW_HIDE As Integer = 0
Private Sub Command1_Click()
On Error GoTo ErrorHandler
Set acc = New Access.Application
Set db = acc.DBEngine.OpenDatabase(strDbName, False, False)
strDbName = "E:\with db\erxp\Copy of dbfiletype.mdb"
acc.OpenCurrentDatabase strDbName
acc.DoCmd.OpenForm "test"
cmd1_Click_exit:
Set db = Nothing
Exit Sub
'WIN API Function to hide the access application
fSetAccessWindow (SW_HIDE)
ErrorHandler:
If Err.Number <> 0 Then
' Handle errors
MsgBox "An unexpected error has occurred." & _
vbCrLf & "Please note of the following details:" & _
vbCrLf & "Error Number: " & Err.Number & _
vbCrLf & "Description: " & Err.Description _
, vbCritical, "Error"
Resume cmd1_Click_exit
End If
End Sub
Under the standard module :
Private Declare Function apiShowWindow Lib "user32" _
Alias "ShowWindow" (ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long
Public Function fSetAccessWindow(nCmdShow As Long)
'Usage Examples
'Maximize window:
' ?fSetAccessWindow(SW_SHOWMAXIMIZED)
'Minimize window:
' ?fSetAccessWindow(SW_SHOWMINIMIZED)
'Hide window:
' ?fSetAccessWindow(SW_HIDE)
'Normal window:
' ?fSetAccessWindow(SW_SHOWNORMAL)
'
Dim loX As Long
Dim loForm As Form
On Error Resume Next
Set loForm = Screen.ActiveForm
If Err <> 0 Then 'no Activeform
If nCmdShow = SW_HIDE Then
MsgBox "Cannot hide Access unless " _
& "a form is on screen"
Else
loX = apiShowWindow(hWndAccessApp, nCmdShow)
Err.Clear
End If
Else
If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then
MsgBox "Cannot minimize Access with " _
& (loForm.Caption + " ") _
& "form on screen"
ElseIf nCmdShow = SW_HIDE And loForm.PopUp <> True Then
MsgBox "Cannot hide Access with " _
& (loForm.Caption + " ") _
& "form on screen"
Else
loX = apiShowWindow(hWndAccessApp, nCmdShow)
End If
End If
fSetAccessWindow = (loX <> 0)
End Function
select a
Data source. Possibly it is asking for the driver. : i am just putting my
code here: i am working in visual basic 6. and trying to hide the
application window and show only form using the win 32 api function written
in standard module.
please help me with this . and
please be a little patient for my querie..
Thanks alot..
here is the code:
In form module i have a code like this:
Dim acc As Access.Application
Dim db As DAO.Database
Dim strDbName As String
Const SW_HIDE As Integer = 0
Private Sub Command1_Click()
On Error GoTo ErrorHandler
Set acc = New Access.Application
Set db = acc.DBEngine.OpenDatabase(strDbName, False, False)
strDbName = "E:\with db\erxp\Copy of dbfiletype.mdb"
acc.OpenCurrentDatabase strDbName
acc.DoCmd.OpenForm "test"
cmd1_Click_exit:
Set db = Nothing
Exit Sub
'WIN API Function to hide the access application
fSetAccessWindow (SW_HIDE)
ErrorHandler:
If Err.Number <> 0 Then
' Handle errors
MsgBox "An unexpected error has occurred." & _
vbCrLf & "Please note of the following details:" & _
vbCrLf & "Error Number: " & Err.Number & _
vbCrLf & "Description: " & Err.Description _
, vbCritical, "Error"
Resume cmd1_Click_exit
End If
End Sub
Under the standard module :
Private Declare Function apiShowWindow Lib "user32" _
Alias "ShowWindow" (ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long
Public Function fSetAccessWindow(nCmdShow As Long)
'Usage Examples
'Maximize window:
' ?fSetAccessWindow(SW_SHOWMAXIMIZED)
'Minimize window:
' ?fSetAccessWindow(SW_SHOWMINIMIZED)
'Hide window:
' ?fSetAccessWindow(SW_HIDE)
'Normal window:
' ?fSetAccessWindow(SW_SHOWNORMAL)
'
Dim loX As Long
Dim loForm As Form
On Error Resume Next
Set loForm = Screen.ActiveForm
If Err <> 0 Then 'no Activeform
If nCmdShow = SW_HIDE Then
MsgBox "Cannot hide Access unless " _
& "a form is on screen"
Else
loX = apiShowWindow(hWndAccessApp, nCmdShow)
Err.Clear
End If
Else
If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then
MsgBox "Cannot minimize Access with " _
& (loForm.Caption + " ") _
& "form on screen"
ElseIf nCmdShow = SW_HIDE And loForm.PopUp <> True Then
MsgBox "Cannot hide Access with " _
& (loForm.Caption + " ") _
& "form on screen"
Else
loX = apiShowWindow(hWndAccessApp, nCmdShow)
End If
End If
fSetAccessWindow = (loX <> 0)
End Function