Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

IF satement

Discussion in 'Information Technology' started by Martin, Jul 28, 2006.

Tags:
  1. Martin

    Martin
    Expand Collapse
    Guest

    Hi,

    I have a password box, but i don't want users to input under 5 characters
    into it, so i want to use if statements as validation. e.g

    if password < 5 message
    if password > 5 then let me in

    Here is the code i have already:

    Private Sub Bttn_SaveAndClose_Click()

    If Me.Password > 5 Then
    MsgBox "Your password must be over 5 chars long"

    End If

    If Me.Password < 5 Then
    DoCmd.Close acForm, "frm_StaffDetails"
    MsgBox "Your computer is now going to log you in"

    End If

    End Sub

    Any help would be greatly appreciated

    Martin
     
  2. Brendan Reynolds

    Brendan Reynolds
    Expand Collapse
    Guest

    You've got your '<' and '>' the wrong way around. Try this (original code
    commented out for comparison) ...

    'If Me.Password > 5 Then
    If Me.Password < 5 Then
    MsgBox "Your password must be over 5 chars long"
    'End If
    Else
    'No need to test length again - if it isn't < 5 then it has to be >= 5
    'If Me.Password < 5 Then
    DoCmd.Close acForm, "frm_StaffDetails"
    MsgBox "Your computer is now going to log you in"
    End If

    BTW: The code will accept a password of five characters, but the message
    says 'over 5 chars'. For consistency and clarity, you might want to either
    change the comparison to < 6, so that the code will only accept a password
    that is *more than* five characters long, as the message implies, or else
    change the message to 'at least 5 chars' instead of 'over 5 chars'.

    --
    Brendan Reynolds
    Access MVP

    "Martin" <Martin@discussions.microsoft.com> wrote in message
    news:742BA3CC-F491-4C66-A03C-9181D0D5CF68@microsoft.com...
    > Hi,
    >
    > I have a password box, but i don't want users to input under 5 characters
    > into it, so i want to use if statements as validation. e.g
    >
    > if password < 5 message
    > if password > 5 then let me in
    >
    > Here is the code i have already:
    >
    > Private Sub Bttn_SaveAndClose_Click()
    >
    > If Me.Password > 5 Then
    > MsgBox "Your password must be over 5 chars long"
    >
    > End If
    >
    > If Me.Password < 5 Then
    > DoCmd.Close acForm, "frm_StaffDetails"
    > MsgBox "Your computer is now going to log you in"
    >
    > End If
    >
    > End Sub
    >
    > Any help would be greatly appreciated
    >
    > Martin
    >
    >
     
  3. Martin

    Martin
    Expand Collapse
    Guest

    thanks for your speedy reply, will try it.

    Thanks

    Martin




    "Brendan Reynolds" wrote:

    > You've got your '<' and '>' the wrong way around. Try this (original code
    > commented out for comparison) ...
    >
    > 'If Me.Password > 5 Then
    > If Me.Password < 5 Then
    > MsgBox "Your password must be over 5 chars long"
    > 'End If
    > Else
    > 'No need to test length again - if it isn't < 5 then it has to be >= 5
    > 'If Me.Password < 5 Then
    > DoCmd.Close acForm, "frm_StaffDetails"
    > MsgBox "Your computer is now going to log you in"
    > End If
    >
    > BTW: The code will accept a password of five characters, but the message
    > says 'over 5 chars'. For consistency and clarity, you might want to either
    > change the comparison to < 6, so that the code will only accept a password
    > that is *more than* five characters long, as the message implies, or else
    > change the message to 'at least 5 chars' instead of 'over 5 chars'.
    >
    > --
    > Brendan Reynolds
    > Access MVP
    >
    > "Martin" <Martin@discussions.microsoft.com> wrote in message
    > news:742BA3CC-F491-4C66-A03C-9181D0D5CF68@microsoft.com...
    > > Hi,
    > >
    > > I have a password box, but i don't want users to input under 5 characters
    > > into it, so i want to use if statements as validation. e.g
    > >
    > > if password < 5 message
    > > if password > 5 then let me in
    > >
    > > Here is the code i have already:
    > >
    > > Private Sub Bttn_SaveAndClose_Click()
    > >
    > > If Me.Password > 5 Then
    > > MsgBox "Your password must be over 5 chars long"
    > >
    > > End If
    > >
    > > If Me.Password < 5 Then
    > > DoCmd.Close acForm, "frm_StaffDetails"
    > > MsgBox "Your computer is now going to log you in"
    > >
    > > End If
    > >
    > > End Sub
    > >
    > > Any help would be greatly appreciated
    > >
    > > Martin
    > >
    > >

    >
    >
    >
     
  4. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    Also, you need to use the Len function:

    'If Me.Password > 5 Then
    If Len (Me.Password) < 5 Then
    MsgBox "Your password must be over 5 chars long"
    'End If
    Else
    'No need to test length again - if it isn't < 5 then it has to be >= 5
    'If Me.Password < 5 Then
    DoCmd.Close acForm, "frm_StaffDetails"
    MsgBox "Your computer is now going to log you in"
    End If


    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "Brendan Reynolds" <brenreyn@discussions.microsoft.com> wrote in message
    news:ej58JA1nGHA.1592@TK2MSFTNGP04.phx.gbl...
    > You've got your '<' and '>' the wrong way around. Try this (original code
    > commented out for comparison) ...
    >
    > 'If Me.Password > 5 Then
    > If Me.Password < 5 Then
    > MsgBox "Your password must be over 5 chars long"
    > 'End If
    > Else
    > 'No need to test length again - if it isn't < 5 then it has to be >= 5
    > 'If Me.Password < 5 Then
    > DoCmd.Close acForm, "frm_StaffDetails"
    > MsgBox "Your computer is now going to log you in"
    > End If
    >
    > BTW: The code will accept a password of five characters, but the message
    > says 'over 5 chars'. For consistency and clarity, you might want to either
    > change the comparison to < 6, so that the code will only accept a password
    > that is *more than* five characters long, as the message implies, or else
    > change the message to 'at least 5 chars' instead of 'over 5 chars'.
    >
    > --
    > Brendan Reynolds
    > Access MVP
    >
    > "Martin" <Martin@discussions.microsoft.com> wrote in message
    > news:742BA3CC-F491-4C66-A03C-9181D0D5CF68@microsoft.com...
    > > Hi,
    > >
    > > I have a password box, but i don't want users to input under 5

    characters
    > > into it, so i want to use if statements as validation. e.g
    > >
    > > if password < 5 message
    > > if password > 5 then let me in
    > >
    > > Here is the code i have already:
    > >
    > > Private Sub Bttn_SaveAndClose_Click()
    > >
    > > If Me.Password > 5 Then
    > > MsgBox "Your password must be over 5 chars long"
    > >
    > > End If
    > >
    > > If Me.Password < 5 Then
    > > DoCmd.Close acForm, "frm_StaffDetails"
    > > MsgBox "Your computer is now going to log you in"
    > >
    > > End If
    > >
    > > End Sub
    > >
    > > Any help would be greatly appreciated
    > >
    > > Martin
    > >
    > >

    >
    >
     
  5. Donald A. Herman

    Donald A. Herman
    Expand Collapse
    Guest

    You may also need to do
    'If Len(Me.Password) > 5 Then

    --
    Donald A. Herman
    Software - Scheduler Pro, Disk Cataloger, Math Wizard
    http://don_herman.tripod.com

    Office Extras, Addins
    http://don_herman.tripod.com/msoextras


    "Martin" <Martin@discussions.microsoft.com> wrote in message
    news:F0695AB6-295B-4C2B-A8B3-6384B5486E06@microsoft.com...
    > thanks for your speedy reply, will try it.
    >
    > Thanks
    >
    > Martin
    >
    >
    >
    >
    > "Brendan Reynolds" wrote:
    >
    >> You've got your '<' and '>' the wrong way around. Try this (original code
    >> commented out for comparison) ...
    >>
    >> 'If Me.Password > 5 Then
    >> If Me.Password < 5 Then
    >> MsgBox "Your password must be over 5 chars long"
    >> 'End If
    >> Else
    >> 'No need to test length again - if it isn't < 5 then it has to be >= 5
    >> 'If Me.Password < 5 Then
    >> DoCmd.Close acForm, "frm_StaffDetails"
    >> MsgBox "Your computer is now going to log you in"
    >> End If
    >>
    >> BTW: The code will accept a password of five characters, but the message
    >> says 'over 5 chars'. For consistency and clarity, you might want to
    >> either
    >> change the comparison to < 6, so that the code will only accept a
    >> password
    >> that is *more than* five characters long, as the message implies, or else
    >> change the message to 'at least 5 chars' instead of 'over 5 chars'.
    >>
    >> --
    >> Brendan Reynolds
    >> Access MVP
    >>
    >> "Martin" <Martin@discussions.microsoft.com> wrote in message
    >> news:742BA3CC-F491-4C66-A03C-9181D0D5CF68@microsoft.com...
    >> > Hi,
    >> >
    >> > I have a password box, but i don't want users to input under 5
    >> > characters
    >> > into it, so i want to use if statements as validation. e.g
    >> >
    >> > if password < 5 message
    >> > if password > 5 then let me in
    >> >
    >> > Here is the code i have already:
    >> >
    >> > Private Sub Bttn_SaveAndClose_Click()
    >> >
    >> > If Me.Password > 5 Then
    >> > MsgBox "Your password must be over 5 chars long"
    >> >
    >> > End If
    >> >
    >> > If Me.Password < 5 Then
    >> > DoCmd.Close acForm, "frm_StaffDetails"
    >> > MsgBox "Your computer is now going to log you in"
    >> >
    >> > End If
    >> >
    >> > End Sub
    >> >
    >> > Any help would be greatly appreciated
    >> >
    >> > Martin
    >> >
    >> >

    >>
    >>
    >>
     
  6. Brendan Reynolds

    Brendan Reynolds
    Expand Collapse
    Guest

    Doh! :-/

    --
    Brendan Reynolds
    Access MVP

    "Douglas J Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
    news:%23y4QuN2nGHA.2068@TK2MSFTNGP02.phx.gbl...
    > Also, you need to use the Len function:
    >
    > 'If Me.Password > 5 Then
    > If Len (Me.Password) < 5 Then
    > MsgBox "Your password must be over 5 chars long"
    > 'End If
    > Else
    > 'No need to test length again - if it isn't < 5 then it has to be >= 5
    > 'If Me.Password < 5 Then
    > DoCmd.Close acForm, "frm_StaffDetails"
    > MsgBox "Your computer is now going to log you in"
    > End If
    >
    >
    > --
    > Doug Steele, Microsoft Access MVP
    > http://I.Am/DougSteele
    > (no e-mails, please!)
    >
    >
    > "Brendan Reynolds" <brenreyn@discussions.microsoft.com> wrote in message
    > news:ej58JA1nGHA.1592@TK2MSFTNGP04.phx.gbl...
    >> You've got your '<' and '>' the wrong way around. Try this (original code
    >> commented out for comparison) ...
    >>
    >> 'If Me.Password > 5 Then
    >> If Me.Password < 5 Then
    >> MsgBox "Your password must be over 5 chars long"
    >> 'End If
    >> Else
    >> 'No need to test length again - if it isn't < 5 then it has to be >= 5
    >> 'If Me.Password < 5 Then
    >> DoCmd.Close acForm, "frm_StaffDetails"
    >> MsgBox "Your computer is now going to log you in"
    >> End If
    >>
    >> BTW: The code will accept a password of five characters, but the message
    >> says 'over 5 chars'. For consistency and clarity, you might want to
    >> either
    >> change the comparison to < 6, so that the code will only accept a
    >> password
    >> that is *more than* five characters long, as the message implies, or else
    >> change the message to 'at least 5 chars' instead of 'over 5 chars'.
    >>
    >> --
    >> Brendan Reynolds
    >> Access MVP
    >>
    >> "Martin" <Martin@discussions.microsoft.com> wrote in message
    >> news:742BA3CC-F491-4C66-A03C-9181D0D5CF68@microsoft.com...
    >> > Hi,
    >> >
    >> > I have a password box, but i don't want users to input under 5

    > characters
    >> > into it, so i want to use if statements as validation. e.g
    >> >
    >> > if password < 5 message
    >> > if password > 5 then let me in
    >> >
    >> > Here is the code i have already:
    >> >
    >> > Private Sub Bttn_SaveAndClose_Click()
    >> >
    >> > If Me.Password > 5 Then
    >> > MsgBox "Your password must be over 5 chars long"
    >> >
    >> > End If
    >> >
    >> > If Me.Password < 5 Then
    >> > DoCmd.Close acForm, "frm_StaffDetails"
    >> > MsgBox "Your computer is now going to log you in"
    >> >
    >> > End If
    >> >
    >> > End Sub
    >> >
    >> > Any help would be greatly appreciated
    >> >
    >> > Martin
    >> >
    >> >

    >>
    >>

    >
    >
     
  7. Martin

    Martin
    Expand Collapse
    Guest

    Thanks for all the help guys, worked great!

    BTW.. what does 'if Len' actually do? does it stand for 'if length'?

    Cheers

    Martin

    "Brendan Reynolds" wrote:

    >
    > Doh! :-/
    >
    > --
    > Brendan Reynolds
    > Access MVP
    >
    > "Douglas J Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
    > news:%23y4QuN2nGHA.2068@TK2MSFTNGP02.phx.gbl...
    > > Also, you need to use the Len function:
    > >
    > > 'If Me.Password > 5 Then
    > > If Len (Me.Password) < 5 Then
    > > MsgBox "Your password must be over 5 chars long"
    > > 'End If
    > > Else
    > > 'No need to test length again - if it isn't < 5 then it has to be >= 5
    > > 'If Me.Password < 5 Then
    > > DoCmd.Close acForm, "frm_StaffDetails"
    > > MsgBox "Your computer is now going to log you in"
    > > End If
    > >
    > >
    > > --
    > > Doug Steele, Microsoft Access MVP
    > > http://I.Am/DougSteele
    > > (no e-mails, please!)
    > >
    > >
    > > "Brendan Reynolds" <brenreyn@discussions.microsoft.com> wrote in message
    > > news:ej58JA1nGHA.1592@TK2MSFTNGP04.phx.gbl...
    > >> You've got your '<' and '>' the wrong way around. Try this (original code
    > >> commented out for comparison) ...
    > >>
    > >> 'If Me.Password > 5 Then
    > >> If Me.Password < 5 Then
    > >> MsgBox "Your password must be over 5 chars long"
    > >> 'End If
    > >> Else
    > >> 'No need to test length again - if it isn't < 5 then it has to be >= 5
    > >> 'If Me.Password < 5 Then
    > >> DoCmd.Close acForm, "frm_StaffDetails"
    > >> MsgBox "Your computer is now going to log you in"
    > >> End If
    > >>
    > >> BTW: The code will accept a password of five characters, but the message
    > >> says 'over 5 chars'. For consistency and clarity, you might want to
    > >> either
    > >> change the comparison to < 6, so that the code will only accept a
    > >> password
    > >> that is *more than* five characters long, as the message implies, or else
    > >> change the message to 'at least 5 chars' instead of 'over 5 chars'.
    > >>
    > >> --
    > >> Brendan Reynolds
    > >> Access MVP
    > >>
    > >> "Martin" <Martin@discussions.microsoft.com> wrote in message
    > >> news:742BA3CC-F491-4C66-A03C-9181D0D5CF68@microsoft.com...
    > >> > Hi,
    > >> >
    > >> > I have a password box, but i don't want users to input under 5

    > > characters
    > >> > into it, so i want to use if statements as validation. e.g
    > >> >
    > >> > if password < 5 message
    > >> > if password > 5 then let me in
    > >> >
    > >> > Here is the code i have already:
    > >> >
    > >> > Private Sub Bttn_SaveAndClose_Click()
    > >> >
    > >> > If Me.Password > 5 Then
    > >> > MsgBox "Your password must be over 5 chars long"
    > >> >
    > >> > End If
    > >> >
    > >> > If Me.Password < 5 Then
    > >> > DoCmd.Close acForm, "frm_StaffDetails"
    > >> > MsgBox "Your computer is now going to log you in"
    > >> >
    > >> > End If
    > >> >
    > >> > End Sub
    > >> >
    > >> > Any help would be greatly appreciated
    > >> >
    > >> > Martin
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
    >
     
  8. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    Len is a VBA function that returns the length of the string passed to it.

    Len("abc") will return 3, Len("abcde") will return 5.

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "Martin" <Martin@discussions.microsoft.com> wrote in message
    news:6A7A8FD1-DE38-4D6A-9091-BD9801EF6DA8@microsoft.com...
    > Thanks for all the help guys, worked great!
    >
    > BTW.. what does 'if Len' actually do? does it stand for 'if length'?
    >
    > Cheers
    >
    > Martin
    >
    > "Brendan Reynolds" wrote:
    >
    > >
    > > Doh! :-/
    > >
    > > --
    > > Brendan Reynolds
    > > Access MVP
    > >
    > > "Douglas J Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
    > > news:%23y4QuN2nGHA.2068@TK2MSFTNGP02.phx.gbl...
    > > > Also, you need to use the Len function:
    > > >
    > > > 'If Me.Password > 5 Then
    > > > If Len (Me.Password) < 5 Then
    > > > MsgBox "Your password must be over 5 chars long"
    > > > 'End If
    > > > Else
    > > > 'No need to test length again - if it isn't < 5 then it has to be >= 5
    > > > 'If Me.Password < 5 Then
    > > > DoCmd.Close acForm, "frm_StaffDetails"
    > > > MsgBox "Your computer is now going to log you in"
    > > > End If
    > > >
    > > >
    > > > --
    > > > Doug Steele, Microsoft Access MVP
    > > > http://I.Am/DougSteele
    > > > (no e-mails, please!)
    > > >
    > > >
    > > > "Brendan Reynolds" <brenreyn@discussions.microsoft.com> wrote in

    message
    > > > news:ej58JA1nGHA.1592@TK2MSFTNGP04.phx.gbl...
    > > >> You've got your '<' and '>' the wrong way around. Try this (original

    code
    > > >> commented out for comparison) ...
    > > >>
    > > >> 'If Me.Password > 5 Then
    > > >> If Me.Password < 5 Then
    > > >> MsgBox "Your password must be over 5 chars long"
    > > >> 'End If
    > > >> Else
    > > >> 'No need to test length again - if it isn't < 5 then it has to be >=

    5
    > > >> 'If Me.Password < 5 Then
    > > >> DoCmd.Close acForm, "frm_StaffDetails"
    > > >> MsgBox "Your computer is now going to log you in"
    > > >> End If
    > > >>
    > > >> BTW: The code will accept a password of five characters, but the

    message
    > > >> says 'over 5 chars'. For consistency and clarity, you might want to
    > > >> either
    > > >> change the comparison to < 6, so that the code will only accept a
    > > >> password
    > > >> that is *more than* five characters long, as the message implies, or

    else
    > > >> change the message to 'at least 5 chars' instead of 'over 5 chars'.
    > > >>
    > > >> --
    > > >> Brendan Reynolds
    > > >> Access MVP
    > > >>
    > > >> "Martin" <Martin@discussions.microsoft.com> wrote in message
    > > >> news:742BA3CC-F491-4C66-A03C-9181D0D5CF68@microsoft.com...
    > > >> > Hi,
    > > >> >
    > > >> > I have a password box, but i don't want users to input under 5
    > > > characters
    > > >> > into it, so i want to use if statements as validation. e.g
    > > >> >
    > > >> > if password < 5 message
    > > >> > if password > 5 then let me in
    > > >> >
    > > >> > Here is the code i have already:
    > > >> >
    > > >> > Private Sub Bttn_SaveAndClose_Click()
    > > >> >
    > > >> > If Me.Password > 5 Then
    > > >> > MsgBox "Your password must be over 5 chars long"
    > > >> >
    > > >> > End If
    > > >> >
    > > >> > If Me.Password < 5 Then
    > > >> > DoCmd.Close acForm, "frm_StaffDetails"
    > > >> > MsgBox "Your computer is now going to log you in"
    > > >> >
    > > >> > End If
    > > >> >
    > > >> > End Sub
    > > >> >
    > > >> > Any help would be greatly appreciated
    > > >> >
    > > >> > Martin
    > > >> >
    > > >> >
    > > >>
    > > >>
    > > >
    > > >

    > >
    > >
    > >
     

Share This Page