command button event based on textbox

siCIVIC1986

Registered User.
Local time
Today, 02:23
Joined
Feb 22, 2010
Messages
12
Hi all

I have another problem which I was hoping another set of eyes could possibly help me out with!

I have attached a screen shot of my form and the following code is linked to the on click event on the cmdOK button:

Code:
Private Sub cmdOK_Click()
    If tbEnter.Value = Null Then
    MsgBox "Please enter reason why Inactive."
    Else: DoCmd.Close
    End If
End Sub

What im trying to achieve is when the user clicks on the ok button I want them to have made sure a value is entered into the textbox otherwise prompt for them to do so or then can click the cancel button.

At the moment when the user clicks the ok button the form closes regardless if there is anything in the text box.

could any body shed some light into what i may be doing wrong please?

Thanks in advance.

Simon Knott
 

Attachments

  • prompt.JPG
    prompt.JPG
    13.6 KB · Views: 187
Try this:

If IsNull(Me.tbEnter) or Me.tbEnter = "" Then
MsgBox "....."
Else
DoCmd.Close
End If
 
Try this:

If IsNull(Me.tbEnter) or Me.tbEnter = "" Then
MsgBox "....."
Else
DoCmd.Close
End If

Thanks That works perfectly, I need to have a similar function for the cancel button but reversed so if the user clicks cancel and there is something in the text box it wont let them close the form as they want to cancel rather then enter a value.
 
Use the Not operator;
Code:
If [B][COLOR="Red"]Not[/COLOR][/B] IsNull(Me.tbEnter) or Me.tbEnter = "" Then
MsgBox "....."
Else
DoCmd.Close
End If
 
Tell us what do you want indeed.
Do you want that the user complete the "tbEnter" inevitable,
or he can do it but must not do it.
 
Hi Thanks to you both, I managed to fix this by when the cancel button is pressed I just make the .value is set to null by the code.

Thanks Again.
 
In the Before Update event of the form:
Code:
If Len(Nz(Me.tbEnter, vbNullString)) = 0 Then
    Cancel = True
    MsgBox "....."
End If
 

Users who are viewing this thread

Back
Top Bottom