Results 1 to 10 of 10
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Combo validation in Form's BeforeUpdate (Acc2k2 (as 2k))

    Hi All,
    I am trying to ensure that an entry is made in 2 combo boxes (cboConnectionTerm and cboConnectionYear). Since it is possible that one or both boxes will have never been entered I am using the Form's BeforeUpdate event. The "bare-bones" code is as follows, without the interactive MsgBox:
    <pre>
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(cboConnectionTerm) Or IsNull(cboConnectionYear) Then
    Cancel = True
    'DoCmd.SetWarnings False
    If IsNull(Me!cboConnectionYear) Then
    Me.cboConnectionYear.SetFocus
    ElseIf IsNull(Me!cboConnectionTerm) Then
    Me.cboConnectionTerm.SetFocus
    End If
    'DoCmd.SetWarnings True
    Else
    'do nothing
    End If
    End Sub
    </pre>


    I get a "You can't go to the specified record" error, after this code has run, if I try and leave the record using a navigation button (Previous, First, New, etc).The error appears in the OnClick of said nav buttons. How can I stop this error from happening or appearing?
    Thank You.

    gdr
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

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

    Re: Combo validation in Form's BeforeUpdate (Acc2k2 (as 2k))

    I believe that your SetFocus commands may not be correct.
    Each command starts with Me., I believe it should be Me!
    HTH
    Pat

  3. #3
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Combo validation in Form's BeforeUpdate (Acc2k2 (as 2k))

    Hi Pat and Thanks,
    I was told a long time ago that the Dot was used to refer to a Property or Method, while the Bang was used to refer to members of a collection. I have, since then, used the Dot for SetFocus since it is a property.
    In this case it shouldn't matter since the controls on a form are members of the form's controls collection. If I've been given questionable or incomplete information or if I have misunderstood (like that's never happened before <img src=/S/stupidme.gif border=0 alt=stupidme width=30 height=30> ) then I would certainly be interested in the correct reasoning.
    That said, I tried and changed the Dots to Bangs with no change in the popup error message.
    Thank you again.

    gdr
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

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

    Re: Combo validation in Form's BeforeUpdate (Acc2k2 (as 2k))

    Sometimes clutching at straws works, this time no go.
    Pat

  5. #5
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Combo validation in Form's BeforeUpdate (Acc2k

    I assume by navigation buttons you mean the ones created by the Command Button wizard, not the built-in ones. You may notice if you use built-in ones in this situation, error msg does not occur. To fix problem with custom navigation buttons, add error handling, as illustrated in this example:
    <pre>Private Sub CommandNext_Click()
    On Error GoTo Err_Handler

    DoCmd.GoToRecord , , acNext

    Exit_sub:
    Exit Sub
    Err_Handler:
    Resume Exit_sub

    End Sub</pre>

    Recommend add similar error handling for all custom navigation command buttons to avoid error messages.

    HTH

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Combo validation in Form's BeforeUpdate (Acc2k2 (as 2k))

    The only place you absolutely *must* use bangs is when referencing a form's controls in a query and when referring to a recordset object's fields. If you use the Me keyword in a form, you don't absolutely need the bang. However, you'll also tangle yourself up when fully referencing a subform and its controls if you try to use dots instead of bangs because you're dealing with layers of members and methods. Controls are members of the form's controls collection, so the dot works. However, if you aren't careful about naming controls and fields with different names, you'll never be sure whether you're referencing the control or its underlying field, which is in a different collection. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Charlotte

  7. #7
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Combo validation in Form's BeforeUpdate (Acc2k

    Hi Mark and Thank you,
    Below is an example of the error handling I have had on each of my navigation buttons along with notation indicating where the appears while stepping through the code. It is this line on any of the navigation buttons (Previous, First, etc.) that gets highlighted:

    <pre>Private Sub cmdNew_Click()
    On Error GoTo cmdNew_Click_Err

    DoCmd.GoToRecord , "", acNewRec

    cmdNew_Click_Exit:
    Exit Sub

    cmdNew_Click_Err:
    MsgBox Error$ '<<<<this is the line that's highlighted when the error appears
    Resume cmdNew_Click_Exit

    End Sub
    </pre>


    I then removed that line, to make it look like your error code, and sunovagun, no annoying popup error message. But isn't this a little like taking the phone receiver off the hook and then saying you didn't receive any phone calls? <img src=/S/confused.gif border=0 alt=confused width=15 height=20> Will this turn around and bite me in the backside if there is a "legitimate" error and I don't get the msgbox? Is this error code there only to resume on error? or does something else occur that I am not aware?
    Thanks again.

    gdr
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  8. #8
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Combo validation in Form's BeforeUpdate (Acc2k2 (as 2k))

    Hi Charlotte,
    Thank you. <img src=/S/cool.gif border=0 alt=cool width=15 height=15>

    gdr
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Combo validation in Form's BeforeUpdate (Acc2k

    During the first phase of development, you might leave the MsgBox instruction in place; I often also display the error nummber:

    MsgBox "Error # " & Err.Number & ": " & Err.Description, vbExclamation

    I then write down the error numbers that occur. Often, you will need to modify your code to get rid of the error, but sometimes, it's an error you can ignore. For example, if you open a report using DoCmd.OpenReport, but it's canceled because the report has no data, you get an error 2501 which can safely be ignored.

    When you have an idea of the errors that might occur, you can change the error handler to something like

    <font face="Georgia">cmdNew_Click_Err:
    Select Case Err.Number
    Case 2501 ' Action canceled
    ' Do nothing
    Case 2105 ' Can't go to record
    Beep
    Case Else ' Report all other errors
    MsgBox Err.Description, vbExclamation
    End Select
    Resume cmdNew_Click_Exit
    End Sub</font face=georgia>

    In fact, if the only statement between <font face="Georgia">cmdNew_Click_Exit</font face=georgia> and <font face="Georgia">cmdNew_Click_Err</font face=georgia> is <font face="Georgia">Exit Sub</font face=georgia>, you might as well omit the Resume instruction, but in many cases, you'll want to do some cleaning up whether the code has run succesfully or not. You would put the "cleaning up" code immediately before the <font face="Georgia">Exit Sub</font face=georgia> instruction.

  10. #10
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Combo validation in Form's BeforeUpdate (Acc2k

    Hi Hans and Thank You,
    That's the added information I needed. <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

    gdr
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

Posting Permissions

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