[ad_1]
I am working on controls for my userform. Basically, I am trying to compare the value entered in a textbox (cbofalk) to a value in a range. If it exceeds the number in that range, then it comes up with a msg box yes/no type of decision. I am driving myself crazy because I cannot for the life of me get it to work. I have scoured this forum and the solutions I have implemented all result in the same issue. I even set up a reference box (falkuclone) just to see if I was appropriately addressing the range (since I am a newb)…it pulls the number I want to look at into the reference box, but when I try to compare that number, or even that range to cbofalk, it just doesn’t understand. I enter 10 into cbofalk and the number to exceed is 8.69 and it just merrily continues without the msgbox? The cell I am trying to reference (“J2”), contains a reference to a cell in a query table, but other than that I can’t think of any oddity surrounding this. I have tried adding Val, doing CInt and even CLng to make sure I am comparing apples to apples, but with the same issue. It just doesn’t flag the msgbox. Here is my original code surrounding the issue:
'code to flag a value outside of the control limits
'looks at value in falkuclone textbox and compares with cobfalk textbox and, if cbofalk is greater, triggers messagebox yes/no.
If Me.cboFalk.Value > falkuclone.Value Then
'message box yes/no logic
messageresult = MsgBox("Your falk value is out of specification. Would you like to enter anyways?", vbYesNo + vbCritical, "Out of Spec")
End If
If messageresult = vbNo Then
Exit Sub
Else
'copy the data to the database
With ws
.Cells(lRow, 1).Value = Me.cboFalk.Value
.Cells(lRow, 2).Value = Me.cboTalk.Value
.Cells(lRow, 3).Value = Me.cboTemp.Value
.Cells(lRow, 4).Value = Me.cbopH.Value
.Cells(lRow, 5).Value = Me.cboPSI.Value
.Cells(lRow, 6).Value = Me.cboDate.Value
hiddenstageone_Click
End With
'clear the userform fields
Me.cboFalk.Value = ""
Me.cboTalk.Value = ""
Me.cboTemp.Value = ""
Me.cbopH.Value = ""
Me.cboPSI.Value = ""
Me.cboFalk.SetFocus
Exit Sub
End If
End Sub
Private Sub UserForm_Activate()
'make the form generate todays date when displayed
Me.cboDate.Value = Format(Now(), "mm/dd/yyyy")
'set the falkuclone textbox to equal J2 value when the userform is pulled up
falkuclone.Value = Sheets("Stage 1").Range("J2").Value
End Sub
Thanks so much for any help.
[ad_2]