If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Information Code
Hi,
I have some fields in my form were may not leave blank ( Required properties is set to yes ). I want when a user leave the field in blank condition and try to saving the record,a message box appear and the cursor automtically move to the blank fields.How to build the code or what is the code? Would somebody help. |
#2
|
|||
|
|||
Information Code
Private Sub txtMyTextBox_Exit(Cancel As Integer)
If Len("" & Me!txtMyTextBox) = 0 Then Cancel = True MsgBox "You can't leave this field blank!" End If End Sub Do the same to every field you want to check. Regards, Graham R Seach Microsoft Access MVP Sydney, Australia "chooriang" wrote in message ... Hi, I have some fields in my form were may not leave blank ( Required properties is set to yes ). I want when a user leave the field in blank condition and try to saving the record,a message box appear and the cursor automtically move to the blank fields.How to build the code or what is the code? Would somebody help. |
#3
|
|||
|
|||
Information Code
On Mon, 18 Dec 2006 15:55:20 +0700, "chooriang"
wrote: Hi, I have some fields in my form were may not leave blank ( Required properties is set to yes ). I want when a user leave the field in blank condition and try to saving the record,a message box appear and the cursor automtically move to the blank fields.How to build the code or what is the code? Would somebody help. I'd suggest using the Form's BeforeUpdate event to check the fields: Private Sub Form_BeforeUpdate(Cancel as Integer) Dim iAns As Integer On Error GoTo Proc_Error If IsNull(Me.txtThisField) Then iAns = MsgBox("Please fill in data for ThisField or click Cancel", _ vbOKCancel) Cancel = True If iAns = vbCancel Then Me.Undo Else Me.txtThisField.SetFocus End If GoTo Proc_Exit End If If IsNull(Me.txtThatField) Then iAns = MsgBox("Please fill in data for ThatField or click Cancel", _ vbOKCancel) Cancel = True If iAns = vbCancel Then Me.Undo Else Me.txtThatField.SetFocus End If GoTo Proc_Exit End If Proc_Exit: Exit Sub Proc_Error: error handling code here Resume Proc_Exit End Sub This can be made much more modular and elegant if you wish but it'll give you a start... John W. Vinson[MVP] |
Thread Tools | |
Display Modes | |
|
|