Restoring a value

B

Bill

In the code below, I've attempted to check a
value entered by the user and restore the
original value if what was entered exceeds
the maximum for the current application. So
far, I've been unsuccessful in restoring what
was saved at open time. Saving of the
restored value (Me.ImageRatio = Ratio) using
Me.Requery after the assignment statement
gives a runtime error related to macro or
function validation rule for the field. I have
not set a validation rule in the property sheet
for the control.

What am I missing here?

Bill

======(Application)====================

Option Compare Database
Dim strRatio As String
______________________________________
Private Sub Form_Open(Cancel As Integer)
Ratio = Me.ImageRatio 'Save current value

End Sub
_______________________________________
Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original value.
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " & vbNewLine & _
"aspect ratio of your images to 1.34 or less."

Me.ImageRatio = strRatio

End If
End Sub

=====================================
 
B

Bill

Got it..........
==========================================
Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original value.
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " & vbNewLine & _
"aspect ratio of your images to 1.34 or less."
Cancel = True
Me!tbImageRatio.Undo

End If
End Sub
==========================================
 
K

Klatuu

There are several problems with your code, but we don't need to go into that.
It is a simple fix.

Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original value.
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " & vbNewLine & _
"aspect ratio of your images to 1.34 or less."
Me.ImageRatio.Undo
Cancel = True
End If
End Sub
 
B

Bill

"several problems with your code". Please
enlighten.
Thanks,
Bill



Klatuu said:
There are several problems with your code, but we don't need to go into
that.
It is a simple fix.

Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original value.
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " & vbNewLine & _
"aspect ratio of your images to 1.34 or less."
Me.ImageRatio.Undo
Cancel = True
End If
End Sub


--
Dave Hargis, Microsoft Access MVP


Bill said:
In the code below, I've attempted to check a
value entered by the user and restore the
original value if what was entered exceeds
the maximum for the current application. So
far, I've been unsuccessful in restoring what
was saved at open time. Saving of the
restored value (Me.ImageRatio = Ratio) using
Me.Requery after the assignment statement
gives a runtime error related to macro or
function validation rule for the field. I have
not set a validation rule in the property sheet
for the control.

What am I missing here?

Bill

======(Application)====================

Option Compare Database
Dim strRatio As String
______________________________________
Private Sub Form_Open(Cancel As Integer)
Ratio = Me.ImageRatio 'Save current value

End Sub
_______________________________________
Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original value.
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " & vbNewLine &
_
"aspect ratio of your images to 1.34 or less."

Me.ImageRatio = strRatio

End If
End Sub

=====================================
 
K

Klatuu

Option Compare Database
Dim strRatio As String <-- Dimmed as String, but your underlying table field
is numeric.

The code below is of no use. Even if it were, the Open event is too soon.
the control objects may not yet be established. Also, Ration is dimmed in
the sub, so is not visible outside the sub.
______________________________________
Private Sub Form_Open(Cancel As Integer)
Ratio = Me.ImageRatio 'Save current value

End Sub

I see nowhere in your code where you assign a value to strRatio
You don't cancel the Before Update, so the update will happen with an
incorrect value
_______________________________________
Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original value.

These brackets are unnecessary and might cause an error
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " & vbNewLine & _
"aspect ratio of your images to 1.34 or less."

Me.ImageRatio = strRatio
---> Cancel = True
to cancel the update of the control.

End If
End Sub


--
Dave Hargis, Microsoft Access MVP


Bill said:
"several problems with your code". Please
enlighten.
Thanks,
Bill



Klatuu said:
There are several problems with your code, but we don't need to go into
that.
It is a simple fix.

Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original value.
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " & vbNewLine & _
"aspect ratio of your images to 1.34 or less."
Me.ImageRatio.Undo
Cancel = True
End If
End Sub


--
Dave Hargis, Microsoft Access MVP


Bill said:
In the code below, I've attempted to check a
value entered by the user and restore the
original value if what was entered exceeds
the maximum for the current application. So
far, I've been unsuccessful in restoring what
was saved at open time. Saving of the
restored value (Me.ImageRatio = Ratio) using
Me.Requery after the assignment statement
gives a runtime error related to macro or
function validation rule for the field. I have
not set a validation rule in the property sheet
for the control.

What am I missing here?

Bill

======(Application)====================

Option Compare Database
Dim strRatio As String
______________________________________
Private Sub Form_Open(Cancel As Integer)
Ratio = Me.ImageRatio 'Save current value

End Sub
_______________________________________
Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original value.
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " & vbNewLine &
_
"aspect ratio of your images to 1.34 or less."

Me.ImageRatio = strRatio

End If
End Sub

=====================================
 
B

Bill

Thank you.
Bill


Klatuu said:
Option Compare Database
Dim strRatio As String <-- Dimmed as String, but your underlying table
field
is numeric.

The code below is of no use. Even if it were, the Open event is too soon.
the control objects may not yet be established. Also, Ration is dimmed in
the sub, so is not visible outside the sub.
______________________________________
Private Sub Form_Open(Cancel As Integer)
Ratio = Me.ImageRatio 'Save current value

End Sub

I see nowhere in your code where you assign a value to strRatio
You don't cancel the Before Update, so the update will happen with an
incorrect value
_______________________________________
Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original value.

These brackets are unnecessary and might cause an error
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " & vbNewLine & _
"aspect ratio of your images to 1.34 or less."

Me.ImageRatio = strRatio
---> Cancel = True
to cancel the update of the control.

End If
End Sub


--
Dave Hargis, Microsoft Access MVP


Bill said:
"several problems with your code". Please
enlighten.
Thanks,
Bill



Klatuu said:
There are several problems with your code, but we don't need to go into
that.
It is a simple fix.

Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original
value.
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " & vbNewLine &
_
"aspect ratio of your images to 1.34 or less."
Me.ImageRatio.Undo
Cancel = True
End If
End Sub


--
Dave Hargis, Microsoft Access MVP


:

In the code below, I've attempted to check a
value entered by the user and restore the
original value if what was entered exceeds
the maximum for the current application. So
far, I've been unsuccessful in restoring what
was saved at open time. Saving of the
restored value (Me.ImageRatio = Ratio) using
Me.Requery after the assignment statement
gives a runtime error related to macro or
function validation rule for the field. I have
not set a validation rule in the property sheet
for the control.

What am I missing here?

Bill

======(Application)====================

Option Compare Database
Dim strRatio As String
______________________________________
Private Sub Form_Open(Cancel As Integer)
Ratio = Me.ImageRatio 'Save current value

End Sub
_______________________________________
Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original
value.
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " & vbNewLine
&
_
"aspect ratio of your images to 1.34 or less."

Me.ImageRatio = strRatio

End If
End Sub

=====================================
 
K

Klatuu

Not trying to beat you up, Bill, just trying to help.
--
Dave Hargis, Microsoft Access MVP


Bill said:
Thank you.
Bill


Klatuu said:
Option Compare Database
Dim strRatio As String <-- Dimmed as String, but your underlying table
field
is numeric.

The code below is of no use. Even if it were, the Open event is too soon.
the control objects may not yet be established. Also, Ration is dimmed in
the sub, so is not visible outside the sub.
______________________________________
Private Sub Form_Open(Cancel As Integer)
Ratio = Me.ImageRatio 'Save current value

End Sub

I see nowhere in your code where you assign a value to strRatio
You don't cancel the Before Update, so the update will happen with an
incorrect value
_______________________________________
Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original value.

These brackets are unnecessary and might cause an error
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " & vbNewLine & _
"aspect ratio of your images to 1.34 or less."

Me.ImageRatio = strRatio
---> Cancel = True
to cancel the update of the control.

End If
End Sub


--
Dave Hargis, Microsoft Access MVP


Bill said:
"several problems with your code". Please
enlighten.
Thanks,
Bill



There are several problems with your code, but we don't need to go into
that.
It is a simple fix.

Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original
value.
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " & vbNewLine &
_
"aspect ratio of your images to 1.34 or less."
Me.ImageRatio.Undo
Cancel = True
End If
End Sub


--
Dave Hargis, Microsoft Access MVP


:

In the code below, I've attempted to check a
value entered by the user and restore the
original value if what was entered exceeds
the maximum for the current application. So
far, I've been unsuccessful in restoring what
was saved at open time. Saving of the
restored value (Me.ImageRatio = Ratio) using
Me.Requery after the assignment statement
gives a runtime error related to macro or
function validation rule for the field. I have
not set a validation rule in the property sheet
for the control.

What am I missing here?

Bill

======(Application)====================

Option Compare Database
Dim strRatio As String
______________________________________
Private Sub Form_Open(Cancel As Integer)
Ratio = Me.ImageRatio 'Save current value

End Sub
_______________________________________
Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original
value.
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " & vbNewLine
&
_
"aspect ratio of your images to 1.34 or less."

Me.ImageRatio = strRatio

End If
End Sub

=====================================
 
B

Bill

Not a problem Dave, I always appreciate the
help I receive in this newsgroup.
Bill



Klatuu said:
Not trying to beat you up, Bill, just trying to help.
--
Dave Hargis, Microsoft Access MVP


Bill said:
Thank you.
Bill


Klatuu said:
Option Compare Database
Dim strRatio As String <-- Dimmed as String, but your underlying table
field
is numeric.

The code below is of no use. Even if it were, the Open event is too
soon.
the control objects may not yet be established. Also, Ration is dimmed
in
the sub, so is not visible outside the sub.
______________________________________
Private Sub Form_Open(Cancel As Integer)
Ratio = Me.ImageRatio 'Save current value

End Sub

I see nowhere in your code where you assign a value to strRatio
You don't cancel the Before Update, so the update will happen with an
incorrect value
_______________________________________
Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original
value.

These brackets are unnecessary and might cause an error
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " & vbNewLine &
_
"aspect ratio of your images to 1.34 or less."

Me.ImageRatio = strRatio
---> Cancel = True
to cancel the update of the control.

End If
End Sub


--
Dave Hargis, Microsoft Access MVP


:

"several problems with your code". Please
enlighten.
Thanks,
Bill



There are several problems with your code, but we don't need to go
into
that.
It is a simple fix.

Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original
value.
MsgBox "The image ratio you entered [" & Me.tbImageRatio & "]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " &
vbNewLine &
_
"aspect ratio of your images to 1.34 or less."
Me.ImageRatio.Undo
Cancel = True
End If
End Sub


--
Dave Hargis, Microsoft Access MVP


:

In the code below, I've attempted to check a
value entered by the user and restore the
original value if what was entered exceeds
the maximum for the current application. So
far, I've been unsuccessful in restoring what
was saved at open time. Saving of the
restored value (Me.ImageRatio = Ratio) using
Me.Requery after the assignment statement
gives a runtime error related to macro or
function validation rule for the field. I have
not set a validation rule in the property sheet
for the control.

What am I missing here?

Bill

======(Application)====================

Option Compare Database
Dim strRatio As String
______________________________________
Private Sub Form_Open(Cancel As Integer)
Ratio = Me.ImageRatio 'Save current value

End Sub
_______________________________________
Private Sub tbImageRatio_BeforeUpdate(Cancel As Integer)
If Me.ImageRatio > 1.34 Then 'Notify user and restore original
value.
MsgBox "The image ratio you entered [" & Me.tbImageRatio &
"]
exceeds the " & vbNewLine & _
"maximum value of 1.34. Please adjust the " &
vbNewLine
&
_
"aspect ratio of your images to 1.34 or less."

Me.ImageRatio = strRatio

End If
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