Default Value

D

David

Having a little problem,
I have got a combobox on a form that looks to another table to retrieve a
value list for tax rates.
The combobox and all works fine, what I am trying to accomplish is to change
the default value on demand through code.
The table that the combobox looks at has 2 fields, a percentage rate the the
decimal equivelent.
The combobox has its default value set to 9.75 which is in the bound column
of 2, I am trying through code to change the value, and it works on the
current new record, but when the record changes it goes back to 9.75.
I am using the following

Private Sub combo9_AfterUpdate()
Dim BytChoice As Byte
BytChoice = MsgBox("Do You need to change the default Tax Rate of " &
Me.combo9 & "% ?", vbQuestion + vbYesNo, "Title of my program")
If BytChoice = vbYes Then
MsgBox "The new rate of " & Me.combo9 & "% will take effect when you
close this form.", vbOKOnly, "Title of my program"
Me.SetRate.DefaultValue = Me.combo9
End If
If BytChoice = vbNo Then
Me.Text10.SetFocus
End If
End Sub

Can this be done?
I would like to specify the rate for ease of use, then when the tax rate
increases(which it does every year) have the user to change it on the form
instead of going too another form.
 
J

Jeff Boyce

David

If the value in the combo box starts out at "9.75" for every record, that's
the definition of a "default" value. If you are saying that when you return
to an already saved record which you changed the value from 9.75 to
something else, but 9.75 is still there, then the combo box is not "bound"
to a field in your table. As an unbound control, it simply shows the same
thing every time.

Or have I misunderstood your situation?
 
D

David

It is bound to a field, which I tried a few other thing with this morning
and I it still is locked at 9.75

I put a textbox bound to the same field and it is showing 9.75 when an older
record is opened. When I execute the code to change the default value it
does change in both the combobox and the textbox, but when you go back to
that record it is still showing 9.75 even though it was change on the
record, and you can go to a new record and it is still showing 9.75.
I took the defaut value out of the combobox and put it in the tables field
and it still produces the same.
Can you suggest another way to accomplish this?
 
D

David

I cured my problem, what I did was to not assign a default value to the
control or in the table, then use this code in the oncurrent of the form
If IsNull(Me.setrate) Or Me.setrate = "" Then
Me.Text9.DefaultValue = DLast("taxrate", "clist")
Exit Sub
End If
If Me.setrate > 0 Then
Me.Text9.DefaultValue = Me.setrate
End If
works fine!
 
M

Marshall Barton

David said:
I cured my problem, what I did was to not assign a default value to the
control or in the table, then use this code in the oncurrent of the form
If IsNull(Me.setrate) Or Me.setrate = "" Then
Me.Text9.DefaultValue = DLast("taxrate", "clist")
Exit Sub
End If
If Me.setrate > 0 Then
Me.Text9.DefaultValue = Me.setrate
End If


Are you sure that you want to set the default to the value
in the last record that was visited? It seems that you were
better off using the AfterUpdate event.

Your use of the DLast function also strikes me as unusual.
Do you understand that it may retrieve a seemingly random
value from the table?

I also thought you wanted to save that value for the next
time the form was opened? I don't see how your code
accomplishes that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top