Hello,
I am a new developer who has been asked to support some VBA code written to automate document generation through a case tool, and I have a question.
When generating the document the user may have the option to pick a config file if more than one config file is associated with the information to be generated. A vb form was created to handle this. The form gets launched if more than one config file is available. This all works correctly. The only problem is that the focus is set on the application launching the document generation, not on the vb form that has been launched. This vb form is associated with Word.
Here is the code that launches the form:
If dlgConfigDialog.ListCount > 1 Then
dlgConfigDialog.Show vbModal
End If
Set dlgConfigDialog = Nothing
I was confused at first because the form is set to vbModal in the code and I thought that this would set the focus to the form. Well a co-worker explained to me that this setting was at the application level and not at the system level. He gave me some code that he thought would fix it.
Here is the code:
Private Declare Function FindWindow Lib "USER32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Declare Function SetSysModalWindow Lib "User" (ByVal hWnd As Integer) As Integer
Dim hWndForm As Long
hWndForm = FindWindow("ThunderDFrame", oForm.Caption)
retval% = SetSysModalWindow(hWndForm)
But every time I try and compile this I get the following error:
Compile Error:
Only comments may appear after End Sub, End Function, or End Property
Like I said I am a new developer, less than 2 months experience, and I would appreciate any direction that can be offered.
I am a new developer who has been asked to support some VBA code written to automate document generation through a case tool, and I have a question.
When generating the document the user may have the option to pick a config file if more than one config file is associated with the information to be generated. A vb form was created to handle this. The form gets launched if more than one config file is available. This all works correctly. The only problem is that the focus is set on the application launching the document generation, not on the vb form that has been launched. This vb form is associated with Word.
Here is the code that launches the form:
If dlgConfigDialog.ListCount > 1 Then
dlgConfigDialog.Show vbModal
End If
Set dlgConfigDialog = Nothing
I was confused at first because the form is set to vbModal in the code and I thought that this would set the focus to the form. Well a co-worker explained to me that this setting was at the application level and not at the system level. He gave me some code that he thought would fix it.
Here is the code:
Private Declare Function FindWindow Lib "USER32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Declare Function SetSysModalWindow Lib "User" (ByVal hWnd As Integer) As Integer
Dim hWndForm As Long
hWndForm = FindWindow("ThunderDFrame", oForm.Caption)
retval% = SetSysModalWindow(hWndForm)
But every time I try and compile this I get the following error:
Compile Error:
Only comments may appear after End Sub, End Function, or End Property
Like I said I am a new developer, less than 2 months experience, and I would appreciate any direction that can be offered.