Need help with 'OK' Message Box -- Getting Error after msg

psulion01

Board Regular
Joined
Sep 25, 2002
Messages
127
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
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
You code looks fine, Is there an event on the ClientFirstName field that runs when the focus is set. It may be that which cause the error.

Have you tried setting a break point in your code and stepping through it line by line (using F8) to double check what is happening?

Peter
 
Upvote 0
Re: Need help with 'OK' Message Box -- Getting Error after m

The OK message box works fine if I either:

1) Remove the 'Me![ClientFirstName].SetFocus' line, or
2) Change 'Me![ClientFirstName].SetFocus' to read 'Me!cmdViewExistingPlans.SetFocus

Either way I still can't set the focus to the ClientFirstNameField. It's not a huge deal, but where could I place the SetFocus control so it runs after the message box is cleared (assuming no client record exists)?

Thx,
Mike
 
Upvote 0
Thats why I was asking if there is any code attatched to the ClientFirstName field as that is the most likly culprit

Peter
 
Upvote 0
Re: Need help with 'OK' Message Box -- Getting Error after m

I just figured it out... the SetFocus command isn't referencing the Text Box name (which is ClientFirstName, same as the name on my table). For some reason the field name is 'First Name' when I look at the drop down of possible subs in the VB editor.

I don't know why all the names are different (table field name vs. captions vs. names in properties dialog box, etc.) It works, but now i need to figure out how things should be named so I'm not wondering what's what later on...

Thanks for the help,
Mike
 
Upvote 0

Forum statistics

Threads
1,221,813
Messages
6,162,117
Members
451,743
Latest member
matt3388

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top