Results 1 to 9 of 9
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862

    CAuto clear a field after error

    How do you clear the displayed selection from a combobox after error? Combobox Alpha must be filled in before filling in comboboz Bravo. I have tried field="", =Null Set field =... Searched the internet, but didn't find it.

    Code is


    Private Sub O6_RECOMMENDATION___VOTE_BeforeUpdate(Cancel As Integer)
    If Me!AO_Recommendation_Vote & "" = "" Then
    MsgBox "AO Recommendation Vote must be filled in first"
    Exit Sub
    End If
    End Sub

    I am pretty sure it will be a one liner.

    Thanks

  2. #2
    drexasaurus's Avatar
    drexasaurus is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    Santa Ana, CA
    Posts
    60
    It seems to me, unless I misunderstand what you're doing, is that you could simply clear the combo box by referring to the control itself: Me.combobox = Null, etc.

    Oh! In the BeforeUpdate event, you want to set Cancel = true to cancel the update in that event.

  3. #3
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    Drexasaurus
    Thanks,
    Tried them both previously. It doesn't clear it other than highlighting the word in the combobox. You have to hit wscape to clear it. Deleting it with delete button still gets the popup.


    I think it has to be returned to null ststus.

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    You can't change the value of a Control in it's BeforeUpdate event...it keeps the Access Gnomes from saving the data, which is the whole point of the BeforeUpdate event. Move the code to the AfterUpdate event:
    Code:
    Private Sub O6_RECOMMENDATION___VOTE_AfterUpdate()
    
     If Me!AO_Recommendation_Vote & "" = "" Then
       MsgBox "AO Recommendation Vote must be filled in first"
       Me.O6_RECOMMENDATION___VOTE=Null 
       AO_Recommendation_Vote.SetFocus
     End If
    
    End Sub


    And just because it looks odd (O6_RECOMMENDATION___VOTE) I'll ask:

    Is the first character Capital O, instead of a Zero?

    Is there really three Underline characters between the O6_RECOMMENDATION and VOTE?

    Linq ;0)>
    Last edited by Missinglinq; 11-07-2014 at 01:55 PM.

  5. #5
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    Ling,
    I tried:
    Private Sub O6_RECOMMENDATION___VOTE_AfterUpdate()
    If Me!AO_Recommendation_Vote & "" = "" Then
    MsgBox "AO Recommendation Vote must be filled in first"
    Me.O6_RECOMMENDATION___VOTE = Null
    AO_Recommendation_Vote.SetFocus
    End If
    End Sub

    There was a period befor the = Me.O6_RECOMMENDATION___VOTE. = Null that I took out. When I got to run it gets a runtime error 424 at the AO_Recommendation_Vote.SetFocus

    O6_(1 _) RECOMMENDATION___ (1 _) VOTE - the extra 2 Access put in itself. the O is a capital O (Officer)

  6. #6
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    I tried the following and it locks it up pretty good. Not what I want.

    Private Sub O6_RECOMMENDATION__VOTE_BeforeUpdate(Cancel As Integer)
    If isNull Me.AO_RECOMMENDATION___VOTE Then
    MsgBox "AO Recommendation Vote must be filled in first"
    Cancel = True
    End If
    End Sub

  7. #7
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    Got it fixed: Access also wanted a triple _ before VOTE and change Me.O6_RECOMMENDATION___VOTE = Null to read Me.AO_RECOMMENDATION___VOTE Now it works like a charm.

    Thanks!

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Sorry about that extraneous period! It is always preferable to not include Spaces in the names of anything, in Access; nor any Special Characters! To separate words, if you will, in names, you really should use a 'camel' or 'humpback' notation, where

    Hump Back Notation

    would become

    HumpBackNotation

    or use Underscores between the parts

    Hump_Back_Notation

    If you left the name as

    Hump Back Notation

    and clicked on an event in the Properties Pane to enter code, the Access Gnomes will, as you found out, add Underscores, and you'd end up with:

    Private Sub Hump_Back_Notation_BeforeUpdate(Cancel As Integer)

    If you're entering code, freehand, and a name has Space(s), you need to place the name inside of Square Brackets:

    If IsNull(Me.[Hump Back Notation] Then

    That tells the compiler that Hump, Back and Notation are all part of a single name.

    Linq ;0)>

  9. #9
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    I already did some name changing. It made some of the stuff a PITA to correct. I knew about the [] and so forth. I think the extra _ came from the name I used at first AO Recommendation - Vote. Access doesn't like the -

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Drop downs error on clear
    By Ruegen in forum Programming
    Replies: 2
    Last Post: 10-31-2013, 12:40 AM
  2. Clear field
    By Fortfury in forum Forms
    Replies: 1
    Last Post: 12-28-2012, 08:20 PM
  3. Need help to clear a Form Field
    By vkumar in forum Access
    Replies: 4
    Last Post: 05-31-2012, 02:18 PM
  4. VBA Error Handling Clear
    By josephff in forum Programming
    Replies: 19
    Last Post: 08-30-2011, 12:12 PM
  5. clear field values
    By surrendertoo in forum Queries
    Replies: 0
    Last Post: 02-23-2008, 10:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums