A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Information Code



 
 
Thread Tools Display Modes
  #1  
Old December 18th, 2006, 09:55 AM posted to microsoft.public.access.forms
chooriang
external usenet poster
 
Posts: 17
Default 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  
Old December 18th, 2006, 11:51 AM posted to microsoft.public.access.forms
Graham R Seach
external usenet poster
 
Posts: 261
Default 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  
Old December 18th, 2006, 07:20 PM posted to microsoft.public.access.forms
John Vinson
external usenet poster
 
Posts: 4,033
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:35 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.