If Statement Problem

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

I have 2 fields, both Number fields.
Whenever I run this if statemnet it always comes out Not Equal.
Any help appreciated.
Thanks
DS

If Me.Text0 = Me.Text2 Then
MsgBox "Equal"
ElseIf Me.Text0 <> Me.Text2 Then
MsgBox "Not Equal"
End If
 
DS said:
I have 2 fields, both Number fields.
Whenever I run this if statemnet it always comes out Not Equal.
Any help appreciated.
Thanks
DS

If Me.Text0 = Me.Text2 Then
MsgBox "Equal"
ElseIf Me.Text0 <> Me.Text2 Then
MsgBox "Not Equal"
End If
This works, but there has to be a better way the problem is that
TxtDisplay must be a string and I need to make it an Integer. Is there
a way of doing that without Dim?
Thanks
DS

Me.TxtPass = Nz(DLookup("[Password]", "tblPasswords", "FormID = 1"), 0)
Dim PASSNUM As Integer
PASSNUM = Me.TxtDisplay
If PASSNUM < Me.TxtPass Or _
PASSNUM > Me.TxtPass Then
Me.Line16.Visible = False
Me.TxtDisplay = ""
Forms!frmPadNumber!LblDisplay.Caption = "PASSWORD"
DoCmd.OpenForm "frmMsgWarning"
Forms!frmMsgWarning!TxtMsg = "INVALID PASSWORD"
Else:
DoCmd.OpenForm "frmFX"
Me.TxtDisplay = Null
Forms!frmPadNumber!LblDisplay.Caption = ""
Forms!frmFX!TxtTaxRate = Forms!frmProServ!TaxRate
Forms!frmFX!TxtTerminalID = Forms!frmProServ!TerminalID
DoCmd.Close acForm, "frmPadNumber"
DoCmd.Close acForm, "frmProServ"
Dim blRet As Boolean
Dim lngColor As Long
lngColor = RGB(128, 128, 128)
blRet = RestoreMDIBackGroundImage(lngColor)
End If
 
DS said:
I have 2 fields, both Number fields.
Whenever I run this if statemnet it always comes out Not Equal.
Any help appreciated.
Thanks
DS

If Me.Text0 = Me.Text2 Then
MsgBox "Equal"
ElseIf Me.Text0 <> Me.Text2 Then
MsgBox "Not Equal"
End If

what if you use
if Val(me.Text0)=val(me.text2) then...
 
Instead of

If PASSNUM < Me.TxtPass Or _
PASSNUM > Me.TxtPass Then


you can use

If CInt(Me.txtdisplay) <> CInt(Me.TxtPass) Then
'invalid passwod
or

If CInt(Me.txtdisplay) = CInt(Me.TxtPass) Then
'valid password


In the following snippet, it is redundent for the "ElseIf" clause.
If it is either TRUE or False.


This is better:

If Me.Text0 = Me.Text2 Then
MsgBox "Equal"
Else
MsgBox "Not Equal"
End If


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


DS said:
DS said:
I have 2 fields, both Number fields.
Whenever I run this if statemnet it always comes out Not Equal.
Any help appreciated.
Thanks
DS

If Me.Text0 = Me.Text2 Then
MsgBox "Equal"
ElseIf Me.Text0 <> Me.Text2 Then
MsgBox "Not Equal"
End If
This works, but there has to be a better way the problem is that
TxtDisplay must be a string and I need to make it an Integer. Is there
a way of doing that without Dim?
Thanks
DS

Me.TxtPass = Nz(DLookup("[Password]", "tblPasswords", "FormID = 1"), 0)
Dim PASSNUM As Integer
PASSNUM = Me.TxtDisplay
If PASSNUM < Me.TxtPass Or _
PASSNUM > Me.TxtPass Then
Me.Line16.Visible = False
Me.TxtDisplay = ""
Forms!frmPadNumber!LblDisplay.Caption = "PASSWORD"
DoCmd.OpenForm "frmMsgWarning"
Forms!frmMsgWarning!TxtMsg = "INVALID PASSWORD"
Else:
DoCmd.OpenForm "frmFX"
Me.TxtDisplay = Null
Forms!frmPadNumber!LblDisplay.Caption = ""
Forms!frmFX!TxtTaxRate = Forms!frmProServ!TaxRate
Forms!frmFX!TxtTerminalID = Forms!frmProServ!TerminalID
DoCmd.Close acForm, "frmPadNumber"
DoCmd.Close acForm, "frmProServ"
Dim blRet As Boolean
Dim lngColor As Long
lngColor = RGB(128, 128, 128)
blRet = RestoreMDIBackGroundImage(lngColor)
End If
 
SteveS said:
Instead of

If PASSNUM < Me.TxtPass Or _
PASSNUM > Me.TxtPass Then


you can use

If CInt(Me.txtdisplay) <> CInt(Me.TxtPass) Then
'invalid passwod
or

If CInt(Me.txtdisplay) = CInt(Me.TxtPass) Then
'valid password


In the following snippet, it is redundent for the "ElseIf" clause.
If it is either TRUE or False.





This is better:

If Me.Text0 = Me.Text2 Then
MsgBox "Equal"
Else
MsgBox "Not Equal"
End If


HTH
Thanks for the input, I do get redundant sometimes so that bit of info
was good!
Thanks
DS
 
Back
Top