Results 1 to 10 of 10
  1. #1
    SemiAuto40 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    41

    Error checking field, SetFocus does not work

    Would some kind individual save my sanity? Please my blood pressure cannot handle this!
    I have a frm_Sample_Login, first control named ProductName is a combo box bound to tbl_Products. I am trying to check to make sure a valid product is chosen and that the user did not just press <Enter> through the field.
    The problem is no matter how that I try to trap the error and return focus to the combo box ProductName, Access2010 will NOT let me return so that my cursor is back blinking in the ProductName field.

    I have a couple more questions on trying to handle errors BEFORE Access


    grabs them but that can wait.

    Thanx.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You can hold the focus in the ComboBox in the Exit Event of the control.

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    what code are you using, and why is your combo box allowing input that is not on the list? Could you not set the property of your combo box limit to list to true? This would prevent any invalid entries.

    If they hit enter off the combo box and it is blank you would want code like:

    if isnull(me.comboboxname) then
    'stay on the active control
    else
    'do whatever you normally do
    endif

  4. #4
    SemiAuto40 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    41

    Error checking SetFocus problems

    As opposed to having a blank field for ProductName once the form opens I placed
    question marks. The problem that I have with using the On Exit Event for the field
    checking below - is that if a user opens the form and then decides for whatever reason to click my "Abort" button to close the form..... There is an endless loop after clicking "Abort" redirecting back to ProductName!

    See code below:

    When the form first opens I assign the ProductName to "?????" for appearances then....... at the On Exit of ProductName_cbox the procedure below.

    If Me!ProductName_cbox = "?????" Then
    MsgBox "You must enter a Product Name"
    Me.SampleIDCode_cbox.Enabled = True
    Me.SampleIDCode_cbox.SetFocus
    Me.ProductName_cbox.Undo
    Me.ProductName_cbox.SetFocus
    End If

    *In addition my "Limit to List" is set to TRUE but that doesn't seem to make a difference in keeping my cursor in the ProductName combo box for some yet unknown reason.

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Is there any chance you could include a sample of your database?

    At first glance I would say if you're closing the form with the X in the upper right corner remove the ability for the user to do that and add a button to your form that does a close and attach code to that button that will handle the perpetual loop of exiting your form that you're experiencing now.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Set a public Boolean flag that you check in the Exit event and reset it when you press the "Abort" button.

  7. #7
    SemiAuto40 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    41
    I hate to be ignorant, but realize I'm self taught with never having had a computer class. Would that Boolean flag be 'global' so that both the 'On Exit' event and the 'DoCMD on the Abort_Sample_Login_Button_Click() both can know the value of it, and if so how do I do that?

    I REALLY appreciate this help because it just takes me so many hours of reading to find precisely what I want to be able to do.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You simply Dim the variable *outside* and before all of your procedures. I will then be "global" as far as that form is concerned and all of the procedures can see and use it. The top of the Form's code (class) module should be something like:
    Code:
    Option Compare Database
    Option Explicit
    Dim YourFlag As Boolean

  9. #9
    SemiAuto40 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    41
    My friend that started me in my programming pursuits preached against global variables (maybe because I wanted to use them for everything), but you guys are GREAT and very knowledgable. I'm glad I picked this forum out of those Google gave me!

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Technically, Global Variables are defined in Standard Modules and not in code modules for forms. I'm not a big fan of them either and rarely use them. What you have defined is a Public Variable in a form and can only be used within that form. Global Variables can be used by *any* form.

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

Similar Threads

  1. Error Checking my Entry Result
    By AKQTS in forum Programming
    Replies: 3
    Last Post: 04-21-2011, 07:46 AM
  2. SetFocus problem
    By JvdP in forum Forms
    Replies: 0
    Last Post: 03-16-2011, 08:55 AM
  3. SetFocus Problem
    By ColPat in forum Programming
    Replies: 2
    Last Post: 06-21-2010, 04:43 AM
  4. Date error checking
    By oediaz in forum Programming
    Replies: 2
    Last Post: 03-26-2010, 12:08 PM
  5. SetFocus Issue
    By Sinjin in forum Access
    Replies: 0
    Last Post: 02-14-2008, 07:31 AM

Tags for this Thread

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