Currenct issue with a text box

E

Eric Brenner

I am having a issue that I am hoping someone has ran into before.

I have a form called frmConfig which users can change configuration
values when needed. When the form first opens, I grab the value and
display it in a text box called 'curHourlyRate' and then set the focus
to the save button on my form. I have the format set to Currency on
the 'curHourlyRate' text box.

When I run the form, the correct value displays but does not format
the displayed value to Currency. It only does this when I change the
value and tab over to my save button.

This is all the code I have, for now:

Private Sub btnConfigSave_Click()
Dim db As DAO.Database, rst As DAO.Recordset, strSQL As String

'Get the current items from the config table
strSQL = "SELECT ConfigValue FROM tblConfig WHERE ConfigName =
'HourlyLaborRate'"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)

With rst
.Edit
!ConfigValue = Me.curHourlyRate.Value
.Update
End With

Set rst = Nothing
Set db = Nothing

End Sub

Private Sub Form_Load()
Dim db As DAO.Database, rst As DAO.Recordset, strSQL As String

'First, turn the forms color to the Normal Form Color
Me.Section("Detail").BackColor = strNormalFormColor

'Get the current items from the config table
strSQL = "SELECT ConfigValue FROM tblConfig WHERE ConfigName =
'HourlyLaborRate'"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)

With rst
Me.curHourlyRate.Value = !ConfigValue
End With

Set rst = Nothing
Set db = Nothing

End Sub

Any ideas?
 
K

Ken Snell

You're doing a lot of unnecessary use of recordsets in your code. Try
changing your Form_Load code to this:


Private Sub Form_Load()
Me.curHourlyRate.Value = CCur(DLookup("ConfigValue", "tblConfig",
"ConfigName = 'HourlyLaborRate'"))
End Sub
 

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