popup msg when text field is empty

le888

Registered User.
Local time
Today, 13:22
Joined
Dec 10, 2003
Messages
344
Hi everyone,

I don't know want happen to my form. I have put some simple code but it seems don't work. I am using "Isnull" function to forced the user to fill the text field. But I have tested it seems nothing happen. I have try to put the code on the main form, it didn't work and I put on the text field itself it didn't work either. And also, I put a checK point in my programmation, this time it works. It seems that it skip the code in a certain point. I don't know why?


Code:
Private Sub txtClientName_BeforeUpdate(Cancel As Integer)
 
             If IsNull(Me.txtClientName) Then
                MsgBox "Add a client name", vbExclamation
                Cancel = True        
             End If
    
End Sub

What's wrong with it, I think this is quit simple?

Thanks in adavance,
Le :confused:
 
That code will only be triggered if you change the value in the textbox ClientName; it won't be triggered if you close the form without editing the textbox.

Put it in the form's BeforeUpdate event.
 
Mile-O-Phile said:
That code will only be triggered if you change the value in the textbox ClientName; it won't be triggered if you close the form without editing the textbox.

Put it in the form's BeforeUpdate event.

Yet, I have try to put in the main form but I don't work either.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

   If IsNull(Me.txtTPMName) Then
        MsgBox "Add TPM Name ", vbExclamation
    Else: MsgBox "TPM name enter" ' I just want to make sure the code is executing but either the first or the second line is executing
    End If
    
End Sub

And this time, I have put a break point, the code skip. Usually, when you put a break point, it shows the execution code. But this time it skip. The form just continue until I add a new requirement and it popup a msg " Don't except a null value on a primary key"

Regards,

Le
 
You do need to type something in to make the form 'dirty' before the BeforeUpdate event will run for the form.
 
Mile-O-Phile said:
You do need to type something in to make the form 'dirty' before the BeforeUpdate event will run for the form.

I am not sure what you mean. I don't use the control "dirty" and don't know what is this control. If you have some ideas, propose me.

Le
 
When you open a new record, it isn't seen as a new record until a value is given to a field within it. An autonumber, for example, isn't assigned until the field has one bit of information.

When a form (bound to a recordset) has information then the Dirty property of the form is False. When a change is made to any of the data in the record displayed then the Dirty property changed to True.

Only when the Dirty property is True, does the BeforeUpdate event run.
 
Mile-O-Phile said:
When you open a new record, it isn't seen as a new record until a value is given to a field within it. An autonumber, for example, isn't assigned until the field has one bit of information.

When a form (bound to a recordset) has information then the Dirty property of the form is False. When a change is made to any of the data in the record displayed then the Dirty property changed to True.

Only when the Dirty property is True, does the BeforeUpdate event run.

So, what should I do, put some code in the dirty event? Is it the same code that I put in the beforeUpdate event?

Thanks for your quick response and working hard on my problem.

Cheers,

Le
 
No. The Dirty event occurs when the form is made Dirty.
 
Code:
Private Sub Form_Unload(Cancel As Integer)
    If IsNull(Me.txtTPMName) Then
        MsgBox "Add TPM Name ", vbExclamation
        Cancel = True
    End If
End Sub
 
Mile-O-Phile said:
Code:
Private Sub Form_Unload(Cancel As Integer)
    If IsNull(Me.txtTPMName) Then
        MsgBox "Add TPM Name ", vbExclamation
        Cancel = True
    End If
End Sub

O.K. it works in a certain point. I have to type a string and erase it and then the popup msg appear. But if I don't type anything and jump to my subform, nothing happens. So, can I force the focus to stay in the text box until they type something?

Thanks again,

Le
 
Alright, i completed a previous database that did this:

I set the field to be required in the table, then enabled custom error checking so that it would catch it if you tried to move on and i set focus back to the text box so that the user wouldnt have to click on it.
________
Vino 125
 
Last edited:
a.sinatra said:
Alright, i completed a previous database that did this:

I set the field to be required in the table, then enabled custom error checking so that it would catch it if you tried to move on and i set focus back to the text box so that the user wouldnt have to click on it.

I don't understand what you mean by setting on the required table.

Here is my proposition:
Can I use the on error event , if so, what is the code number for error on primary key ? And can you tell me how to get these error number ?

Thanks,

Le
 
This is what i am talking about, this is located in the table design view.
________
NUMMI
 

Attachments

  • untitled.GIF
    untitled.GIF
    15.3 KB · Views: 131
Last edited:
le888 said:
O.K. it works in a certain point. I have to type a string and erase it and then the popup msg appear. But if I don't type anything and jump to my subform, nothing happens. So, can I force the focus to stay in the text box until they type something?

Thanks again,

Le


Use the Before insert event of the subform,
If IsNull(Me.SomeControl) Then
etc
 
Rich said:
Use the Before insert event of the subform,
If IsNull(Me.SomeControl) Then
etc

Hi guys,

A great thanks for u guys. Rich, your solution don't work. I found one:

Code:
Private Sub txtTPMName_Exit(Cancel As Integer)

    If IsNull(Me.txtTPMName) Then
        MsgBox "Add TPM Name sortie"
        Me.txtTPMName.SetFocus
        Cancel = True
    End If

End Sub

I have try until now, I didn't see any side effect. But if u guys see something, please tell me.

P.S. Rich, why when you reply to me, I don't receive in my mail box. Is it normal because other person who reply to me, I see in my mail box? I see your email only when I return to this forum.

Thanks again,

Le ;) :D
 

Users who are viewing this thread

Back
Top Bottom