Connecting Tech Pros Worldwide Help | Site Map

conditional statement for field in form

Newbie
 
Join Date: Aug 2007
Posts: 5
#1: Aug 22 '07
I am new to access.

I have a form titled "form1" with a textfield titled "code." If the textfield "code" is left blank in the form by the person submitting the form and they click submit, then I want to check the field "code" to see if it is blank (empty), and if it is, input into the table "clients" under column "client_code" the value "tem." If the field is not blank, then I would like to use whatever the user input into the field. All other fields in the form would be irrelevant as to whether they have values or not, they will be submitted as is.

Can anyone set me up in the right direction for this? Or provide me with an example?

Thanks
Richard
JKing's Avatar
Moderator
 
Join Date: Jun 2007
Location: Niagara Falls, Ontario
Posts: 557
#2: Aug 23 '07

re: conditional statement for field in form


I'm assuming the form is bound and that the control source for the textbox code is client_code. Use the before update event to check if the textbox is null if so set the textbox equal to "tem"

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate()
  2. If IsNull(Me.code) Then
  3. Me.code = "tem"
  4. End If
  5. End Sub
  6.  
Newbie
 
Join Date: Aug 2007
Posts: 5
#3: Aug 24 '07

re: conditional statement for field in form


Quote:

Originally Posted by JKing

I'm assuming the form is bound and that the control source for the textbox code is client_code. Use the before update event to check if the textbox is null if so set the textbox equal to "tem"

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate()
  2. If IsNull(Me.code) Then
  3. Me.code = "tem"
  4. End If
  5. End Sub
  6.  


Thanks a lot. It works!

Richard
Reply


Similar Microsoft Access / VBA bytes