There is Hope. Here are some items to check:
1. [Population Bracket] is a bound textbox and bound to the correct field in
the database.
2. The code is in the Before Update event of the text box [Population
Bracket]
3. [Population Bracket] is not diabled or locked.
4. Check the values of [CountyPopulation] and [CityPopulation], they may not
be null when you expect them to be.
:
Correct. I'm not changing any typed in value; and I've been attempting to
run the code in Before Update. Is their hope?
--
Tom
:
'69,
The only time the Case Else will execute is if the condition in the select
returns a null, a negative number, or any positive number up to .9999. For
every other number, one of the case statements will kick in first. Also,
where is he changing a value typed in? I don't see it. What I do see is the
code is the an After Update event. Shouldn't it be in the Before Update
event of the Population Bracket text box?
:
Hi, Tom.
I'm not getting a result. Can anybody figure out why?
Yes. Your code is attempting to change the value typed into the text box
before the bound text box is updated. Your code should be attempting to
change the value in another control, not the same control.
Also, can you
recommend how I can get a default value of 1, should neither city or county
population options be choosen?
Use the Case Else statement as the default value. Your current Case Else
value is probably only intended to apply if the population is over 200,000,
but that 3.5 multiplier will be applied as the default for all cases not
covered, which isn't what you want. To get the effects you want, I'd
recommend something like the following VBA code:
' * * * * Start Code * * * *
Private Sub txtSomething_AfterUpdate()
On Error GoTo ErrHandler
Dim Result As Single
Select Case Nz(Me!CountyPopulation.Value, Me!CityPopulation.Value)
Case 1 To 20000
Result = 1
Case 20001 To 40000
Result = 1.5
Case 40001 To 100000
Result = 2.5
Case 100001 To 200000
Result = 3
Case Is > 200000
Result = 3.5
Case Else
Result = 1
End Select
Me!PopulationBracket.Value = Result
Exit Sub
ErrHandler:
MsgBox "Error in txtSomething_AfterUpdate( ) in " & vbCrLf & _
Me.Name & " form." & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
End Sub
' * * * * End Code * * * *
... where PopulationBracket is the name of the bound text box that holds the
assigned billing multiple for the current population, and txtSomething is the
name of the text box that is being updated with a value during the course of
filling in the form. With the above logic, if both the county and city
populations have values (boo boos do happen), then the county population will
be used for the billing multiplier.
It might be better to have a command button that the user can click on to
calculate the billing multiplier, but if users tend to forget steps, then the
code should be doing as much automation as possible and an AfterUpdate( )
event is fine for this.
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are (e-mail address removed) and (e-mail address removed)
- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts as "Answers,"
so that all may benefit by filtering on "Answered questions" and quickly
finding the right answers to similar questions. Remember that the first and
best answers are often given to those who have a history of rewarding the
contributors who have taken the time to answer questions correctly.
:
I'm using this code to populate a bound textbox [PopulationBracket] that
yields a billing multiple based on population depending on which non-null
population is choosen (City or County but never both):
Private Sub PopulationBracket_BeforeUpdate(Cancel As Integer)
Select Case Nz(CountyPopulation, CityPopulation)
Case 1 To 20000
Result = 1
Case 20001 To 40000
Result = 1.5
Case 40001 To 100000
Result = 2.5
Case 100001 To 200000
Result = 3
Case Else
Result = 3.5
End Select
Me.PopulationBracket = Result
End Sub
I'm not getting a result. Can anybody figure out why? Also, can you
recommend how I can get a default value of 1, should neither city or county
population options be choosen? Many thanks.