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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-time error '3251' when checking for Dirty from form

Status
Not open for further replies.

d1trupinoy

Technical User
Dec 11, 2001
14
US
I am trying to build a module that will write a log everytime Dirty is true. Right now I just call this module from various forms using the Before Update event. Some forms it works fine but other forms cause an error 3251 - Operation is not supported for this type of object. It will happen on a text box, combo box, etc. I have no idea why. Why will some forms work fine and others not work fine. The error highlights "ctrl.OldValue" as the object that "Operation is not supported for this type of object". Some combo boxes work with this code while others cause the 3251 error. Some text boxes work fine while others cause the error. Forms are based on queries, tables, etc. Any idea or thought would be greatly appreciated.

Sub LogGenerator(FormFocus As Form)
If FormFocus.Dirty Then
MsgBox "Data has changed"
Dim ctrl As Control

For Each ctrl In FormFocus.Controls
If ctrl.ControlType = acTextBox Then
If ctrl.Visible = True Then
MsgBox "acTextBox IF Statement"
MsgBox (ctrl.Name)
MsgBox ("ctrl.Value = " & ctrl.Value)
MsgBox ("ctrl.OldValue = " & ctrl.OldValue)
If ctrl.Value <> ctrl.OldValue Then
MsgBox ctrl.Name & &quot; has changed to &quot; & ctrl.Value
End If
End If
End If
If ctrl.ControlType = acComboBox Then
If ctrl.Visible = True Then
MsgBox &quot;acComboBox IF Statement&quot;
MsgBox (ctrl.Name)
MsgBox (&quot;ctrl.Value = &quot; & ctrl.Value)
MsgBox (&quot;ctrl.OldValue = &quot; & ctrl.OldValue)
If ctrl.Value <> ctrl.OldValue Then
MsgBox ctrl.Name & &quot; has changed to &quot; & ctrl.Value
End If
End If
End If
If ctrl.ControlType = acCheckBox Then
If ctrl.Visible = True Then
MsgBox &quot;acCheckBox IF Statement&quot;
MsgBox (ctrl.Name)
MsgBox (&quot;ctrl.Value = &quot; & ctrl.Value)
MsgBox (&quot;ctrl.OldValue = &quot; & ctrl.OldValue)
If ctrl.Value <> ctrl.OldValue Then
MsgBox ctrl.Name & &quot; has changed to &quot; & ctrl.Value
End If
End If
End If
Next ctrl

Else
MsgBox &quot;OK&quot;
'Refresh
End If
End Sub
 
This probably isn't it, but if I'm not mistaken, the OldValue property only exists for bound controls. You're not trying to use it with unbound controls, are you? Rick Sprague
 
No I checked on that. What I found is that when you update some controls on a form (like a combo box) it actually updates other fields to different records. Therefore I think I cannot compare OldValue and Value for those fields since they were basically switched. Is there a way to find out if a field refers to a new record source instead of seeing if the value was changed?
 
What version of Access are you using? In both Access 97 and Access 2000, error 3251 comes up &quot;Invalid use of property&quot; rather than what you report. If you're using Access XP, I probably should bow out, as I have no experience with it yet.

I don't understand what you mean by &quot;it actually updates other fields to different records.&quot; Your form only has one current record (unless there's a subform involved). To access other records during the BeforeUpdate event, you'd have to use code--but if that were so, you would have known about it already, instead of having to find out about it. And what do you mean by &quot;if a field refers to a new record source&quot;? Record sources are properties of forms, not fields. Sorry if I'm being dense, I just can't figure out what you're saying. I guess it's the terminology you're using. Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top