adding expressions as default values to forms (1 Viewer)

bali3377

Registered User.
Local time
Today, 04:19
Joined
Jan 31, 2010
Messages
13
Hello, Does anyone know if it is possible to add anything other than simple text or numbers to default values on form fields?
I have a subform for orders on a Form for Customers. I would like to put a default value on one of the subform fields that equalls one of the fields on the customer form. It cannot be a straight look up field as sometimes the fields are not the same. There are two fields I want to do one is a tick box another is a text field.
Any ideas
Bali
 

boblarson

Smeghead
Local time
Today, 04:19
Joined
Jan 12, 2001
Messages
32,059
You can change the default value in the subform's On Current event. The default won't be added to a record until a new record is started. It won't affect existing records.

So, for example, in the subform's On Current event:
Code:
Private Sub Form_Current()
  If Me.Parent.CheckBoxNameHere Then
     Me.MyTextBoxName.DefaultValue = Me.TextBoxName1
  Else
     Me.MyTextBoxName.DefaultValue = Me.TextBoxName2
  End If
End Sub
 

bali3377

Registered User.
Local time
Today, 04:19
Joined
Jan 31, 2010
Messages
13
that is very neat!! I will have a go
thanks
 

boblarson

Smeghead
Local time
Today, 04:19
Joined
Jan 12, 2001
Messages
32,059
I may have errored slightly.

After thinking about it, I think you need to use:
Code:
Private Sub Form_Current()
  If Me.Parent.CheckBoxNameHere Then
     Me.MyTextBoxName.DefaultValue = [B][COLOR=red]"=" &[/COLOR][/B] Me.TextBoxName1
  Else
     Me.MyTextBoxName.DefaultValue = [B][COLOR=red]"=" & [/COLOR][/B]Me.TextBoxName2
  End If
End Sub
 

bali3377

Registered User.
Local time
Today, 04:19
Joined
Jan 31, 2010
Messages
13
The Value is for a field called 'HasEUVATno' in the Orders Subform and the Master field is EUVATno in "SupplCustForm' The question is: what will happen if i need to override the default with an occasional No. Ie: someone with a VAT no decides to buy something quickly online with Debit card and pay VAT at point of sale.
 

bali3377

Registered User.
Local time
Today, 04:19
Joined
Jan 31, 2010
Messages
13
which will the database save : the coded 'Yes' or my input of 'No'
 

boblarson

Smeghead
Local time
Today, 04:19
Joined
Jan 12, 2001
Messages
32,059
The code I gave changes the default value. Defaults come into play when a record is added but anyone can overtype the default with their value and it will store the typed value. There is no difference in the default's behavior than if you set it at table level.
 

Users who are viewing this thread

Top Bottom