フォームのOn Open, On Closeイベント、それから各コマンドボタンののOn
Clickイベントに以下のVBAコードを追加します。イメージのOn
Clickイベントには、Windowsのコモンダイアログを表示するためのコードを追加します。
リスト1-各種イベント処理用コード
Dim mobjUsers As Object ' clsMyBox
Private Sub cmdRun_Click()
Dim varBuffer As Variant
Dim intRet As Integer
Dim intI As Integer
Dim strMDBFullPath As String
Dim lngOptions As Long
mobjUsers.Clear
If Nz(Me!txtFullPath) <> "" Then
strMDBFullPath = Me!txtFullPath
lngOptions = Me!grpOptions
intRet = GetUsers_FS(strMDBFullPath, lngOptions, varBuffer)
With mobjUsers
If IsArray(varBuffer) Then
For intI = LBound(varBuffer) To UBound(varBuffer)
If Nz(varBuffer(intI)) <> "" Then
.AddItem CStr(intI + 1) & " " & varBuffer(intI)
End If
Next intI
.AddItem "# of Users = " & intRet
Else
.AddItem varBuffer
.AddItem "Error Code = " & intRet
End If
End With
End If
End Sub
Private Sub cmdQuit_Click()
DoCmd.Quit
End Sub
Private Sub Form_Close()
Dim varRet As Variant
varRet = CloseMyBox_FS("I", mobjUsers)
End Sub
Private Sub Form_Open(Cancel As Integer)
Set mobjUsers = GetMyBox_FS("I")
Set mobjUsers.Control = Me!lstResult
End Sub
Private Sub imgCommDialog_Click()
Dim strFullPath As String
strFullPath = OpenFile_FS("C:\", "Please Select a MDB|MDE file!")
If Len(strFullPath) > 0 Then
Me!txtFullPath = strFullPath
End If
Me!txtFullPath.SetFocus
End Sub