Full Version: Default Value
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
robUK
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.
Doug Steele
Try something like the following for the form's BeforeUpdate event:
!--c1-->
CODE
Private Sub Form_BeforeUpdate(Cancel As Integer)
  
  If Len(Me![Cast No] & vbNullString) = 0 Then
    Me!Checklist = Null
  End If
  
End Sub
robUK
Can't seem to get that to work either.
Doug Steele
Any error?
If not, are you sure that the code is running?
robUK
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
!--c1-->
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.
Doug Steele
You certain you've got the names of the controls properly?
WIW, I've always considered it a very bad idea to include special characters (which includes spaces!) in the names of fields or controls.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.