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

Formatting issue in data validation 1

Status
Not open for further replies.

thepope77

Technical User
Jul 1, 2003
26
US
Hi:

I am running some data validation dealing with tolerances. For example:

Private Sub txtElongation_BeforeUpdate(Cancel As Integer)
Dim MinElong As Double, MaxElong As Double

Select Case Me.cboWireSize

Case "0.172": MinElong = 10: MaxElong = 40
Case "0.175": MinElong = 10: MaxElong = 40
Case "0.182": MinElong = 15: MaxElong = 35
Case "0.200": MinElong = 10: MaxElong = 40
Case "0.209": MinElong = 15: MaxElong = 35
Case "0.227": MinElong = 15: MaxElong = 35
Case "0.270": MinElong = 15: MaxElong = 35
Case "0.330": MinElong = 15: MaxElong = 35

End Select

If Me.txtElongation < MinElong Or Me.txtElongation > MaxElong Then
MsgBox &quot;The elongation is out of spec. Please see that your entry is correct, otherwise PLACE THIS REEL ON HOLD!!&quot;, _
vbCritical, &quot;ELONGATION OUT OF SPEC.&quot;
Cancel = True
End If

End Sub

When the user makes a selection from cboWireSize that ends in a zero, like 0.200 or 0.330, and then enter data in txtMeasuredDiameter, they get the OUT OF SPEC!! msgbox even if what they entered was correct.

I think this is a formatting issue but am not sure. Any help would be greatly appreciated. Thanks a lot.
 
Hi

You are using Doubles, but you have no dec places, so why not use LOng or Integer data type and force the txtbox (Me.txtElongation ) to the same type (eg CInt(Me.txtElongation ).

Doubles do not give perfect (decimal) precision and this may be your problem

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Actually, I would go the other way--convert Me.cboWireSize to a Single using CSng(), and remove the quotes from the Case selectors. Note that VBA will remove the trailing zeros from the latter automatically.


Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
RickSpr:

Thank you very much. It was the quotes! I had no idea it would be that simple. Appreciate the help.

Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top