PC Review


Reply
Thread Tools Rate Thread

Currenct issue with a text box

 
 
Eric Brenner
Guest
Posts: n/a
 
      6th Jan 2012
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?
 
Reply With Quote
 
 
 
 
Ken Snell
Guest
Posts: n/a
 
      7th Jan 2012
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

--

Ken Snell
http://www.accessmvp.com/KDSnell/




"Eric Brenner" <(E-Mail Removed)> wrote in message
news:4da58353-6250-44c3-9024-(E-Mail Removed)...
>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?



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:44 AM.