Results 1 to 10 of 10
  1. #1
    jkk is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    9

    Require an entry in either of two fields, but not both

    Hello, I suspect my problem requires some VBA code, which I know nothing about. In any case, here's the scenario.



    In a table, I'd like to require an entry in either Field A or Field B. But an entry should be in only one of the two fields.

    Thanks.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Then should be only one field with options.

    Then can set the field as Required in table setup.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    jkk is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    9
    Thanks for the reply. Perhaps I'm not understanding, or perhaps I didn't explain my question clearly. I'll try again.

    I'd like an entry to be required in either Field A, or Field B. For a particular record, an entry must be made in either Field A, or Field B. But only one of said fields can have an entry.

    I guess I'm going have to explain the table structure to make it clear what I'm trying to accomplish.

    * The table in question is called "Interactions."
    * Field A is a foreign key field that will pull data from another table. Field A and the foreign-key table are both called "Customers."
    * Field B is identical in structure, but both the field itself and the foreign-key table are called "Vendors."

    So, in the Interactions table, I'd like to record data based on interactions with either Customers or Vendors. A record in the Interactions table must have an entry in one of those fields, but can't have an entry in both.

    So here's the crux of my problem: I understand how to set fields as Required. However, what I don't know how to do is to set up the "either/or" logic I described above.

    Thanks again.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    An odd structure. But okay, need VBA. The real trick is figuring out what event to put code in, perhaps the form BeforeUpdate. Maybe like:

    If (Not IsNull(Me.FieldA) And Not IsNull(Me.FieldB)) Or (IsNull(Me.FieldA) And IsNull(Me.FieldB)) Then
    MsgBox "Must enter data to either FieldA or FieldB, not both."
    Cancel = True
    Me.FieldA = Null
    Me.FiledB = Null
    Me.FieldA.SetFocus
    End If
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    jkk is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    9
    Hi, thanks again, June7. I'm leaving the office for the weekend, will give your suggestion a try next week.

    Hope your weekend is great!

  6. #6
    jkk is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    9
    June7, I tried to insert the VBA code for the form, but no go. I suspect it's my ineptness with VBA, rather than your code. At this point, it's clear that I should spend some time engaging with a VBA tutorial - which I dearly wish to do, however, I lack such time at present.

    So I'm going to have to abandon this aspect of my Access project for now, and unfortunately, this thread. I'm inclined to leave the thread open in case someone else wants to pick it up. But I'll leave it to your discretion as a forum moderator whether or not to leave it open.

    In any case, thanks for the help offered.

  7. #7
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    I tried to insert the VBA code for the form, but no go.
    What exactly does that mean. What actually happened.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  8. #8
    jkk is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    9
    Bob Fitz, I mean nothing happened. The code had absolutely no effect. The form for the Interactions table is also used as a subform, and I suspect this may be adding more complexity than I have skills to negotiate. I tried a few things in the VBA window to get some kind of result. But really, I'm just mucking about.

    Bottom line is I wasn't able to apply the code successfully, and I need to learn some basic VBA skills before proceeding further. If y'all want to turn this thread into a VBA tut (which I doubt, but. . .) be my guest. As I said, I don't have time right now go further with this. Sorry if I've wasted anyone's time. I'm out.

    Cheers.

  9. #9
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Perhaps you could post a copy of the db. We may be able to make the required changes and you could study them at your leisure.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    How did you 'insert the VBA'?

    In the BeforeUpdate event property of form, select [Event Procedure]. Then click the ellipsis (...) to open the VBA editor with the event procedure. Type code.

    Refer to link at bottom of my post for debugging guidelines.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 6
    Last Post: 09-27-2012, 08:27 AM
  2. Calculated Fields in Entry Form
    By Rhubie in forum Forms
    Replies: 1
    Last Post: 09-05-2012, 01:17 PM
  3. Replies: 2
    Last Post: 08-02-2011, 07:25 AM
  4. Replies: 6
    Last Post: 05-05-2011, 08:50 AM
  5. SetFocus/Require Entry
    By mbake085 in forum Programming
    Replies: 5
    Last Post: 08-19-2010, 07:32 AM

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