Default Value

  • Thread starter Thread starter Todd
  • Start date Start date
T

Todd

Would someone tell me how to set the following type of
default value.

I've got 2 check boxes in a form, one for training and one
for live. What I'd like to do is when the check box for
training is selected, another field in the form (msnnbr)
is populated with a set text automatically (EX: the field
will populate the value of "FUN000222") and if the live
check box is selected, the msnber field is blank.

When the training check box is selected all I want to do
is enter three additional numbers in the field.

Help!
 
Would someone tell me how to set the following type of
default value.

I've got 2 check boxes in a form, one for training and one
for live. What I'd like to do is when the check box for
training is selected, another field in the form (msnnbr)
is populated with a set text automatically (EX: the field
will populate the value of "FUN000222") and if the live
check box is selected, the msnber field is blank.

This isn't really a place for the Default property of a field.
Instead, you can use VBA code in the AfterUpdate event of the
checkbox.

Select the checkbox in form design view, look at its Properties, and
click the ... icon by the "AfterUpdate" property; choose the Code
Builder. Put code like the following:

Private Sub chkTraining_AfterUpdate()
If Me!chkTraining = True Then ' if they set the checkbox
Me!msnnbr = "FUN000222"
Else
Me!msnnbr = NULL ' clear the box if they uncheck Training
End If
End Sub
When the training check box is selected all I want to do
is enter three additional numbers in the field.

"the field"? What field? Would it be enough just to set focus to the
control and let the user enter something?
 
First, are you using the two check boxes together or
independently? If the choice is EITHER live OR training,
group them together. If a choice is live AND training,
keep them separate like you probably have them.

Now, on populating the other field you call msnnber:

Enter the following code to the on exit, or on update
property of the training checkbox:

If Me![TrainingBoxName] = -1, then
Me![msnnbr]= "FUN000222"
 
Sorry... I accidently hit the [Tab] key then the [Enter]
key which sent it. Anyway...

If Me![TrainingBoxName]= -1 then
Me![msnnbr] = "FUN000222"
DoCmd.GotoControl "msnnbr"
End If

Another thing you can do is to have msnnbr control
invisible UNTIL it is needed. To do this, make the
visible property of msnnbr set to No. Then make the code
in the training box as follows:

If Me![TrainingBoxName]= -1 then
Me![msnnbr].Visible = -1
Me![msnnbr] = "FUN000222"
DoCmd.GotoControl "msnnbr"
End If

Then, in the OnCurrent property of the FORM, you have to
add the following code to make it invisible again:

If IsNUll(Me![msnnbr]) then Me![msnnbr].Visible = 0 Else
Me![msnnbr].Visible = -1

I would have to play around to get the cursor to go to the
end of the msnnbr field so it is ready to take further
entry, but you can do that, right?

email me if you have any problems.
 
The field is the field I was talking about populating
(msnnbr). I was talking about only adding three
additional numbers at the end of the "FUN000222"
manually. Because the first part "FUN000222" will never
change under training but at the end of it the julian date
001-365 needs to be added.
 
The field is the field I was talking about populating
(msnnbr). I was talking about only adding three
additional numbers at the end of the "FUN000222"
manually. Because the first part "FUN000222" will never
change under training but at the end of it the julian date
001-365 needs to be added.

ummm... Sorry, but this is probably unwise on a couple of levels.

Storing multiple records all of which have FUN000222 seems pointless.
Will other records have other values?

Storing two values - FUN000222 and a date - in the same field is bad
design. A field should be "atomic" - if you have a code and a date,
you should have a field for the code and a different field for the
date.

Making the user manually figure out the day of the year (that's NOT a
Julian Date!) and type it in is a wide-open invitation to error. Why
not use the Date() function to store today's date in a Date/Time
field? You can set the format of the field to "y" to display the day
of the year.

I'm not sure how you use msnnbr in your application - but it seems to
me that you need to revisit its structure!
 
Back
Top