UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Default Value, Office 2003    
 
   
robUK
post Jan 6 2011, 08:38 AM
Post #1

UtterAccess Veteran
Posts: 315



I have a form, which has a control with a Default Value. I need to hide this value or make it null, if the value of another control is also null. Both are text fields.
ie, Checklist has a default value of "Xray". If [Cast No] is blank, I don't want "Xray" to appear. I've tried all sorts of code, but nothing has worked, and I wondered if it was because I had set the default value in the table.
Go to the top of the page
 
+
Doug Steele
post Jan 6 2011, 08:50 AM
Post #2

UtterAccess VIP
Posts: 17,797
From: Don Mills, ON (Canada)



Try something like the following for the form's BeforeUpdate event:

CODE
Private Sub Form_BeforeUpdate(Cancel As Integer)
  
  If Len(Me![Cast No] & vbNullString) = 0 Then
    Me!Checklist = Null
  End If
  
End Sub
Go to the top of the page
 
+
robUK
post Jan 6 2011, 11:07 AM
Post #3

UtterAccess Veteran
Posts: 315



Can't seem to get that to work either.
Go to the top of the page
 
+
Doug Steele
post Jan 6 2011, 11:09 AM
Post #4

UtterAccess VIP
Posts: 17,797
From: Don Mills, ON (Canada)



Any error?

If not, are you sure that the code is running?
Go to the top of the page
 
+
robUK
post Jan 7 2011, 05:57 AM
Post #5

UtterAccess Veteran
Posts: 315



I've been making some changes to the database, which meant some control names changed. The control names are now Cast_No_2, which replaces Cast_No, and Others_2, which replaces Checklist. This is the code I have

CODE
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me![Cast No 2] & vbNullString) = 0 Then
    Me![Others_2] = Null
  End If
End Sub

The control Others_2, does appear blank, but only for 1 record, and on leaving the form, I get an error saying Microsoft Office Access can't find the field 'Others_2', and asks me if I want to debug. If I just select 'End', I am taken back to the form, and the control 'Others_2' is blank. What I'm trying to achieve is, if Cast_No_2 is blank, so is Others_2, if not, the default text should appear.
Go to the top of the page
 
+
Doug Steele
post Jan 7 2011, 06:15 AM
Post #6

UtterAccess VIP
Posts: 17,797
From: Don Mills, ON (Canada)



You certain you've got the names of the controls properly?

FWIW, I've always considered it a very bad idea to include special characters (which includes spaces!) in the names of fields or controls.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 18th June 2013 - 08:01 PM