Please see the code below. Basically I have a Client sheet that has a button to "View Existing Plans". The button works if there is a client record, but I want a message box to pop up if you try to view plans when no client record exists. The message box works fine, but once I click 'OK' i get the error message "Object doesn't support this property or method". The last part of my code below is to set the active field (.SetFocus) to 'ClientFirstName' when no client record exists, and this doesn't occur. Can anyone explain this error? I'm new to VB programming and am pulling a lot from the Northwind database, just picking things apart to learn the code behind the functions.
Thanks,
Mike
-----------------------------
Private Sub cmdViewExistingPlans_Click()
On Error GoTo Err_cmdViewExistingPlans_Click
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
Dim strDocName As String, strLinkCriteria As String
' If ClientFirstName control is blank, display a message.
If IsNull(Me![ClientFirstName]) Then
strMsg = "Move to the client's record whose plans you want to see, then press the 'View Existing Plans' button again."
intStyle = vbOKOnly
strTitle = "Select a Client"
MsgBox strMsg, intStyle, strTitle
Me![ClientFirstName].SetFocus
Else
' Otherwise, open Plans form, showing plans for current client.
strDocName = "frmPlans"
strLinkCriteria = "[ClientID] = Forms![frmClients]![ClientID]"
DoCmd.OpenForm strDocName, , , strLinkCriteria
DoCmd.MoveSize (1440 * 0.78), (1440 * 1.8)
End If
Exit_cmdViewExistingPlans_Click:
Exit Sub
Err_cmdViewExistingPlans_Click:
MsgBox Err.Description
Resume Exit_cmdViewExistingPlans_Click
End Sub
Thanks,
Mike
-----------------------------
Private Sub cmdViewExistingPlans_Click()
On Error GoTo Err_cmdViewExistingPlans_Click
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
Dim strDocName As String, strLinkCriteria As String
' If ClientFirstName control is blank, display a message.
If IsNull(Me![ClientFirstName]) Then
strMsg = "Move to the client's record whose plans you want to see, then press the 'View Existing Plans' button again."
intStyle = vbOKOnly
strTitle = "Select a Client"
MsgBox strMsg, intStyle, strTitle
Me![ClientFirstName].SetFocus
Else
' Otherwise, open Plans form, showing plans for current client.
strDocName = "frmPlans"
strLinkCriteria = "[ClientID] = Forms![frmClients]![ClientID]"
DoCmd.OpenForm strDocName, , , strLinkCriteria
DoCmd.MoveSize (1440 * 0.78), (1440 * 1.8)
End If
Exit_cmdViewExistingPlans_Click:
Exit Sub
Err_cmdViewExistingPlans_Click:
MsgBox Err.Description
Resume Exit_cmdViewExistingPlans_Click
End Sub