Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2009
    Location
    Franklin, OH
    Posts
    44

    Exclamation Unanswered: Make a textbox required based on combo box selction

    I have a combo box that is populated through a query. The query includes information as to whether a PO# is required for a customer. If a PO is required, I have a a MsgBox popup informing the user, the PO textbox turns red, and the cursor is moved to the PO textbox. The textbox in unbound, and not required by default. What I would like to do is make the PO textbox required when the Msgbox & other stuff happens. Currently the IF statement looks like:

    If Me.cbo_DeliveryID.Column(9) = True Then
    MsgBox ("Input PO# for this Customer as REQUIRED")
    txt_PO.SetFocus
    txt_PO.BackColor = vbRed
    Else
    txt_PO.Value = ""
    txt_PO.BackColor = vbWhite
    End If

    I cannot figure out the code to make the PO textbox required before the ELSE statement.
    *NOTE* I cannot make PO text required by default because some of the choices in the combo box do not require PO #'s.
    Any help would be greatly appreciated. Thank You in advance.

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Have a look at the "Validation Rule" and "Validation Text" properties.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Aug 2009
    Location
    Franklin, OH
    Posts
    44

    Question

    Thanks for the quick response Teddy.

    I have tried the Validation Rule (since the field only gets focus when the PO# is required, I thought this would be a great idea), but it does not seem to work. I can still TAB or click out of the textbox, and close the form without any required text in the field. I tried: 1) Is Not Null & 2) <>0 as the validation rule, but neither worked.

    Would you have another suggestion, or could there be a way to code it in the IF statement?

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    What's in your field?

    Did you check for ""?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    Aug 2009
    Location
    Franklin, OH
    Posts
    44
    I did not check for "", If I enter nothing (leave it blank), nothing happens. I can just enter the rest of the data without any requirement of a PO#. How would I check for "" in the validation field?

  6. #6
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    <> "" ?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  7. #7
    Join Date
    Aug 2009
    Location
    Franklin, OH
    Posts
    44
    I have tried <>"". I just cannot seem to get the field to become required when the focus is given. Would there be some VB code I could insert in the IF statement?

  8. #8
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    If you want the field to be required under any condition I think you're going to have to have the field bound to a field in the underlying table. Why in the world would you want this to be an unbound textbox?
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  9. #9
    Join Date
    Aug 2009
    Location
    Franklin, OH
    Posts
    44
    The textbox is unbound because not every customer requires a PO# and I do not need to save the PO# in the database for customers that do want a PO# so there is no field in any table that could be bound to the PO#. But a PO# needs to be displayed on the screen before the form is printed, as required. This is why the IF statement is in there.

    I guess what I would like to know is: Is there VB code to make an object required that I can include in my code?

  10. #10
    Join Date
    Aug 2009
    Location
    Franklin, OH
    Posts
    44
    Any thoughts?

Posting Permissions

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