Add Default Text To Form On Load (1 Viewer)

Tor_Fey

Registered User.
Local time
Today, 15:28
Joined
Feb 8, 2013
Messages
121
Good Morning All;

Is there a way to add default text on a form when it loads via vba?

I have a form (frm_add_targets), which has 15 fields on it and I would like to add default text to these fields if the field should be null.

For example: one of my form fields is called: w_text1 and I would like to default the value of this field to the following: Significant amount of revenue at risk 1)<50k,2)up to .5mil,3)up to 3mil,4)up to 5 mil,5)>5 mil should it be empty on load,

Any help on this would be appreciated :).

Kind Regards
Tor Fey
 

spikepl

Eledittingent Beliped
Local time
Today, 16:28
Joined
Nov 3, 2010
Messages
6,144
Decide what you want exactly.

An existing record has values (or perhaps Nulls) and those do not get changed by setting defaults. Defaults are applied only at the exact moment when a new record is created.
 

Tor_Fey

Registered User.
Local time
Today, 15:28
Joined
Feb 8, 2013
Messages
121
Thanks for your reply but after thinking about it, I have found the solution as follows:

Private Sub Form_Load()
If IsNull(w_text1) Or w_text1 = "" Then
w_text1 = "Significant amount of revenue at risk 1)<50k, 2)up to .5mil, 3)up to 3mil, 4)up to 5 mil, 5)>5 mil"
Else
'do nothing
End If
End Sub

This is working a treat :)
 

spikepl

Eledittingent Beliped
Local time
Today, 16:28
Joined
Nov 3, 2010
Messages
6,144
What you have done here is not common practice. It means that you in your database have existing records, but are unhappy with the values stored.

Normal practice is only to store completed records, or records that, knowingly, will undergo processing. Defaults are added upon creation, or values can be added when triggered by some other value actively being stored in a field. Here you have some strange in-between creature, which isn't ready until it's ready.
 

Tor_Fey

Registered User.
Local time
Today, 15:28
Joined
Feb 8, 2013
Messages
121
Hi Skipepl;

The form field I am defaulting text to is unbound, and would only update the main table when an append query is run from the update record button, so the way I have set this form up has no real consequence on the database as a whole, as it isn't adding records until the update button is clicked?

Regards
Tor Fey
 

Users who are viewing this thread

Top Bottom