Default Series

  • Thread starter Thread starter RMires
  • Start date Start date
R

RMires

Is there any way to step through a series of defaults in a control? For
example, for the first record, have A as the default, then B, then C, then
start over at A, B, C, A, etc.
 
Yes, but the problem is knowing where to start on any given data entry
session. By that, I mean when you close the form last time, the last record
you entered was a "B", so how do you know that or do you always start with
"B"? Not knowing your business rules, I can't tell you the logic to select
which value to use. The business rules for this also will determine where
and when you change the Default Value setting.
 
Yes, it should start with the same each day. I'm entering a volume pumped of
gasoline additive each day, but there are seven different brands. It will
usually be the same order, but not necessarily. The volumes come off of a
report in order of brand everyday, so for ease of entry I'd like to have the
each brand come up as the default in order. The only other way I can think of
would be to pre-fill the table, but that doesn't seem the best way to do it
to me.
 
Any time you consider pre-filling tables, slap yourself in the head, take a
coffee break, and start over <g>

Okay assuming you will start at the same place each day and you will be
going A, B, C, A, B ,C, etc. Here is a plan.

In the form Load event, set the beginning default value for the control.

Me.txtBrand.DefaultValue = "A"

Then in the Form After Update event, change it:

Dim strLastBrand As String

strLastBrand = Me.txtBrand.DefaultValue
Select Case strLastBrand
Case Is "A"
Me.txtBrand.DefaultValue = "B"
Case Is "B"
Me.txtBrand.DefaultValue = "C"
Case Is "C"
Me.txtBrand.DefaultValue = "A"
End Select
 
Let's pretend for a moment that I'm new to access and don't really have much
programming experience...

I assume I can put the
Me.txtBrand.DefaultValue = "A"
into the code builder. Does the "Me" translate into the form name?
The form is named frmEntry, and the Text Box is named Tank. I put
frmEntry.Tank.DefaultValue = "A"
and got a Variable not Defined Error
 
Me refers to the form the code module belongs to.
For fully qualified code it would be:
Forms!frmEntry!Tank.DefaultValue = "A"
But you can use either
Me!Tank.DefaultValue = "A"
or
Me.Tank.DefaultValue = "A"
 
I forgot about putting forms! before the form name. I'm slowly getting there
though. It's accepting the code now, but instead of "A" I'm getting a #name?
The control is actually a combo box with a table as the control source.
Could this be a problem?
 
A table can't be a control source. A control source is either a field in the
form's record source or an expression that returns and displays a value.
If "A" is in the combo's list, it should work.
Post your code so I can have a look.
Also, include the row source of the combo and what is in the Control Source
property of the combo.
 
I'm sorry, the table is the Row Source. The Brand Names are listed in a field
called Tank in both tables.

Form: frmEntry
Combo Box: ctlTank
Tables: tblEntry (frmEntry's Record Source)
tblTanks (ctlTank's Row Source)

Control Source of the Combo is Tank

Code:
Private Sub Form_Load()
Me.ctlTank.DefaultValue = "A"
End Sub
 
Oops! My Bad. The default value has to be expressed as a string in quotes,
so we have to include th quotes in the string. Should be:

Private Sub Form_Load()

Me.ctlTank.DefaultValue = """A"""

End Sub

Notice the nice indenting that makes code easier to read :)

Now that is (expanded for visibility)

" " " A " " "
 
Well, good. I certainly did my share of the fumbling <g>
The newsgroup editor is much more forgiving of syntax than VBE.
 
What is the "newsgroup editor"?

Klatuu said:
Well, good. I certainly did my share of the fumbling <g>
The newsgroup editor is much more forgiving of syntax than VBE.
 
Back
Top