Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Coding not quite working (2000)

    Hi,
    Below is some coding I've been workin on but haven't quite got right. Could someone kindly advice me as to where I'm going wrong?
    I basically want to check whether the field Estimate is Null and then exit the sub. If it is not Null I want it to do as in the code, by focusing the user on CboFeesClerk and filling an entry.

    Private Sub CboFeesClerk_Exit(Cancel As Integer)
    If IsNull(Me.Estimate) Then
    Exit Sub

    If IsNull([CboFeesClerk]) Then

    MsgBox " Please enter a valid name! ", vbInformation, "You have not entered a name"

    Cancel = True
    Me.CboFeesClerk.SetFocus
    Exit Sub
    End If
    End Sub

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Coding not quite working (2000)

    Try moving the EndIf up as in:
    Private Sub CboFeesClerk_Exit(Cancel As Integer)
    If IsNull(Me.Estimate) Then
    Exit Sub
    End If
    If IsNull([CboFeesClerk]) Then

    MsgBox " Please enter a valid name! ", vbInformation, "You have not entered a name"

    Cancel = True
    Me.CboFeesClerk.SetFocus
    Exit Sub

    End Sub

  3. #3
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Coding not quite working (2000)

    Hi,
    This seemed to work!
    Private Sub CboFeesClerk_Exit(Cancel As Integer)
    If IsNull(Me.Estimate) Then
    Exit Sub
    End If
    If IsNull([CboFeesClerk]) Then

    MsgBox " Please enter a valid name! ", vbInformation, "You have not entered a name"

    Cancel = True
    Me.CboFeesClerk.SetFocus
    Exit Sub
    End If
    End Sub
    Presumably this is right? Thanks for the help!

  4. #4
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Coding not quite working (2000)

    Nigel

    This version may be better suited, it checks for 0 and empty string.
    You could go further a trim the field to make sure it contains no spaces, but this should be suffice.
    Also I've moved your "vbInformation" to the end of the msgbox just before the title "Error".


    <pre>Private Sub CboFeesClerk_Exit(Cancel As Integer)
    If IsNull(Me.Estimate) Or Me.Estimate = 0 Or Me.Estimate = "" Then
    Exit Sub
    End If

    If IsNull([cboFeesClerk]) Or Me.cboFeesClerk = 0 Or Me.cboFeesClerk = "" Then

    MsgBox " Please enter a valid name! " & vbCrLf & _
    "You have not entered a name", vbInformation, "Error"

    Cancel = True

    Me.cboFeesClerk.SetFocus

    Exit Sub
    End If
    End Sub</pre>


  5. #5
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Coding not quite working (2000)

    Thanks Dave, works a treat!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •