Results 1 to 9 of 9
  1. #1
    RLehrbass is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    102

    return to empty field before closing


    I have a form that requires a specific combo box selection completed prior to closing or it doesn't register the field ID# in the table or display the payment in the payment query. When I click on the accept button on the form, if [PaymentMethodID] is blank, I want to put up a msg box informing me to "choose a Payment Method", then return the cursor to [PaymentMethodID] field to allow the user to make the appropriate selection.
    How would I write that in VBA.

  2. #2
    RLehrbass is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    102
    I am thinking it will look something like this but it doesn't like the .setfocus in the statement.

    'If IsNull(Me.PaymentMethodID) Then
    ' MsgBox "Please select a Payment Method!"
    ' Me.PaymentMethodID.SetFocus
    'End If

  3. #3
    RLehrbass is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    102
    The Me.PaymentMethodID.SetFocus is giving me a Compile Error; Method or Data member not found

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    I don't think you can use Me in code for a button click, so it's choking when compiling at run-time. Use the explicit form reference:
    Forms!MyFormName.PaymentMethodID.SetFocus
    You might be able to use Me if you referenced the controls collection as well, but it's more coding than is necessary - even if it works.

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Is PaymentMethodID the control source of your combo? Try setting focus on your combo.

    Me.ComboName.Setfocus
    Me.ComboName.Dropdown

    Instead of evaluating the value of your PaymentMethodID, you could evaluate the value of the combo in the combo's afterupdate event.

  6. #6
    RLehrbass is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    102
    Here is my code right now,

    If IsNull(Me.PaymentMethodID) Then
    Beep
    MsgBox "Please select a Payment Method!"
    Me.PaymentMethodID.SetFocus
    Me.PaymentMethodID.Dropdown
    End If

    My CBO control source is: PaymentMethodID.
    My Row Source is: SELECT tblPaymentMethod.ID, tblPaymentMethod.PaymentMethod FROM tblPaymentMethod;

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by RLehrbass View Post
    Here is my code right now, ...
    And this is working? If it is throwing an error on Set Focus it is probably because there is not a control named PaymentMethodID in your form. You may have a field named PaymentMethodID that is part of the Form's Recordset but the SetFocus method is only a member of controls. In other words, a user cannot select a field within a recordset but they can select a Textbox Control.

    Code:
    If IsNull(Me.PaymentMethodID) Then
            Beep
            MsgBox "Please select a Payment Method!"
            Me.ComboName.SetFocus
            Me.ComboName.Dropdown
        End If

  8. #8
    RLehrbass is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    102
    Ok...
    I am sure it is in the construction of the code because I setfocus on the non-CBO field just below the CBO and it works just fine.
    I would like to know what I am doing wrong. I am thinking it has something to do with needing to address column1 in the CBO address
    Column0 is the PaymentMethodID
    Column1 is the PaymentMethod

    IE: Me.PaymentMethodID.Column1.setfocus
    Me.PaymentMethodID.Column1.DropDown

    What do you think???

  9. #9
    RLehrbass is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    102
    I am so sorry. Brain Fart on my part.
    I did not realize what you where actually saying until just now...CBO's NAME...
    the name is cboPaymentMethod.

    New WORKING code is:
    If IsNull(Me.PaymentMethodID) Then
    Beep
    MsgBox "Please select a Payment Method!"
    Me.cboPaymentMethod.SetFocus
    Me.cboPaymentMethod.Dropdown
    Else ...

    Thank you so much. SOLVED

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

Similar Threads

  1. Return records with empty combobox value
    By vincentsp in forum Queries
    Replies: 2
    Last Post: 02-18-2015, 04:41 PM
  2. Replies: 12
    Last Post: 10-22-2014, 02:11 PM
  3. Closing form, return contol to menu form
    By ssissons in forum Programming
    Replies: 11
    Last Post: 05-01-2014, 02:55 PM
  4. Replies: 2
    Last Post: 04-23-2012, 10:13 PM
  5. Return all fields even if lookup is empty
    By skarden in forum Access
    Replies: 2
    Last Post: 05-11-2011, 10:44 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