Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture a Field/No Edits Allowed 3

Status
Not open for further replies.

Stangleboy

Programmer
May 6, 2002
76
US
I have a field (logs.HourlyRate) I need to copy data from another field (classes.HourlyRate) and have it so it never updates by copying the field again. Example: In 2004 nurses rate is $17.25, this field will need to be captured. On 5-23-2005 the rate is $18.65, but I do not want to change the previous records that were done in 2004 with 2005 rates when a user corrects or adds information on the old records. I was trying to do this as easy as possible, like not allowing edits to a field after data has been saved to the record. Any suggestions? Thanx!
 
Try only allowing updates when field value is zero.

Have a great day!

j2consulting@yahoo.com
 
Today is my really stupid day, how do i do this? Thank you.
 
How are ya Stangleboy . . . . .

Can Do! . . . just a few questions first:
[ol][li][blue]logs.HourlyRate[/blue] & [blue]classes.HourlyRate[/blue] are in the same [purple]table?[/purple][/li]
[li][blue]logs.HourlyRate[/blue] & [blue]classes.HourlyRate[/blue] are in the same [purple]form/subform . . . what?[/purple][/li]
[li]Give the [blue]actual names[/blue] of specific items.[/li][/ol]

Calvin.gif
See Ya! . . . . . .
 
Thank you for your help, please see below for the follow-up:

Can Do! . . . just a few questions first:

logs.HourlyRate & classes.HourlyRate are in the same table? Yes
logs.HourlyRate & classes.HourlyRate are in the same form/subform . . . what? Same form.
Give the actual names of specific items. 1. On the form- classes.HourlyRate and log.HourlyRate.
 
Stangleboy . . . . .

I started writing the code when an [blue]ambiguity[/blue] stopped me (you'll have to forgive me here) . . .
[blue]Example: In [blue]2004 nurses rate is $17.25[/blue], this field will need to be captured. [blue]On 5-23-2005 the rate is $18.65[/blue], [purple]but I do not want to change the previous records that were done in 2004 with 2005 rates[/purple] when a user corrects or adds information on the old records.[/blue]
If I understand this correctly, what you really need is a way to [blue]lock rates once a record is saved.[/blue] Also, rates should be required before a record is saved.

Is this correct?

Calvin.gif
See Ya! . . . . . .
 
Yes. I can do it on the Sequel back-end. Once that field is entered and then the record is saved the user can not change, needs an adminstrator. But I prefer to do it on the front-end.
 
Stangleboy . . . . .

Sorry to get back late. getting home this evening was a disaster!

I decided to use the [blue]BeforeUpdate event[/blue] of the form to detect [purple]no data entered[/purple] and [purple]previous data entered[/purple] when [purple]user attempts to save a rcord[/purple]. This [blue]keeps mesages from popping up[/blue] when the user is simply tabbing thru records.

All you do is let you code/method update [blue]HourlyRate[/blue] normally. The following code (copy/paste to the [blue]BeforeUpdate event[/blue] of the form) does the rest.
Code:
[blue]   Dim Msg As String, Style As Integer, Title As String, DL As String
   
   DL = vbNewLine & vbNewLine
   
   If Trim(Me![[b]logs.HourlyRate[/b]] & "") = "" Then
      Msg = "'Hourly Rate' has no Data Entry!" & DL & _
            "The Database will not let you continue until 'Hourly Rate' is satisified!" & DL & _
            "Click 'Yes' to enter 'Hourly Rate' . . ." & DL & _
            "Click 'No' to abort and cancel/delete the current record . . ." & DL & _
            "(Contact Administration if you have any questions about this . . .)"
      Style = vbCritical + vbYesNo
      Title = "No 'Hourly Rate' Error! . . ."
      
      If MsgBox(Msg, Style, Title) = vbYes Then
         Cancel = True
         Me![[b]logs.HourlyRate[/b]].SetFocus
      Else
         Me.Undo
         Me![[b]logs.HourlyRate[/b]].SetFocus
      End If
   ElseIf Not IsNull(Me![[b]logs.HourlyRate[/b]].OldValue) Then
      Msg = "Sorry! . . . You can't change 'Hourly Rate'!" & DL & _
            "'Hourly Rate' is locked once a record is saved . . ." & DL & _
            "Contact Administration to have 'Hourly Rate' changed . . ."
      Style = vbCritical + vbOKOnly
      Title = "Hourly Rate Locked Notice! . . ."
      MsgBox Msg, Style, Title
      Me.Undo
   End If[/blue]
[purple]Thats it! . . . give it a whirl & let me know . . .[/purple]

Calvin.gif
See Ya! . . . . . .
 
Assume your form has 2 fields on it, 1) txtLogsRate and 2) txtClassesRate. In the OnCurrent event code put something like this:
Code:
txtLogsRate.Enabled = (Nz(txtLogsRate) <> 0)
txtLogsRate.Locked = Not txtLogsRate.Enabled
If you set enable to False and Locked to True you don't get the disabled coloring on the disabled control. Good Luck!

Have a great day!

j2consulting@yahoo.com
 
Another approach.

Add a field to the rate table. Define it as a boolean / yes / no data type. Call it LockedRecord, defualt value is "No". The yes/no control check box is hidden on the form. (visible property is set to "No").

Now after committing the record, set the LockedRecord to yes.

With the BeforeUpdate event procedure
Code:
Me.LockedRecord = True

Then coding becomes simpler. For the OnCurrent event procedure
Code:
Dim booLocked as Boolean

booLocked = Me.LockedRecord

Me.[logs.HourlyRate] = booLocked 
Me.[classes.HourlyRate] = booLocked

Richard
 
SBendBuckeye! . . . . Willir! . . . .

and if the form is in [purple]Continuous View?[/purple]

Calvin.gif
See Ya! . . . . . .
 
Hi AceMan

Good question.

In contineous view, would not the OnCurrent event control edit access depending on the value of Me.LockedRecord for the current record???
 
willir . . . . .

Sorry, yours is fine old friend! I was referring to [blue]SBendBuckeye's[/blue] use of the enabled property . . .

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top