click event of a command button

reena

Registered User.
Local time
Today, 00:54
Joined
Jul 18, 2001
Messages
17
Hi
I have a company form, in which there is a command button which would open a form basically a list box for the user to select different sectors the company belongs.
When there is a record already with company_id the command button works fine, but if a user by mistake choose to select to enter a new company record and before entering
if they happen to click on the add sectors command button then opens a debug window.

I am trying to code in such away when a user clicks on the command button without a new record entry it should display a error message instead the debug screen

Basically in the click event of the command button I have this code

If Me.txtCompany_ID = "" Then
MsgBox ("You have to enter a company_ID first to select the sectors")
Else
DoCmd.OpenForm "frmSectors", acNormal, , , acFormEdit, acDialog, Me.txtCompany_ID
LstSectors.Requery
DoEvents
End If

But still it is not working

Could any one help me with this

Thanks a lot in advance
 
Try If IsNull(Me.txtCompany_ID) Then
MsgBox "You have to enter a company_ID first to select the sectors"
End If
End Sub
Else
DoCmd.OpenForm "frmSectors", acNormal, , , acFormEdit, acDialog, Me.txtCompany_ID
LstSectors.Requery
 
Thanks Rich,

Regards
 

Users who are viewing this thread

Back
Top Bottom