Results 1 to 10 of 10
  1. #1
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171

    Conditional code for form

    Hello all,

    I have this form "Orders" with two sub forms "Deliveries" and "Order_Detail".
    I want that if combo "Department" and "Location" is empty and I click there in forms "Deliveries" or "Order_Detail" then


    it should give me message that "Please select Department and Location first".
    So what and where code will be used?
    Secondly in form "Deliveries" when I click on New blank record then after entering new record, it should give me message that "Enter Date first".

    Thanks in advance.

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    What are the row sources for your combos?
    I think you could do a record count on the Row source and display a message depending on the row count.

    You might be able to have the some controls be invisible, until a proper value was received???
    You could use some instructions on the Form to assist users also.

    Tell us more about why and how DEPARTMENT and/or LOCATION could be empty.

  3. #3
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    I want that if user not select Department and Location then he should not able to enter data in sub forms.
    and if you want to know more about my database then please visit this thread you will get all information.Thanks
    https://www.accessforums.net/forms/form-designing-29111.html
    https://www.accessforums.net/forms/f...tml#post145021

  4. #4
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    I put this code in sub form "Deliveries" "before update" event
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Len(Me.ORDERID & vbNullString) = 0 Then
    MsgBox "Select Department and Location First"
    Cancel = True

    End If
    End Sub

    But there is already one code in sub form "Deliveries" "before insert" event.
    which was working fine before this code.
    But now it gives error.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I've never used form BeforeInsert or BeforeUpdate events but if you want to provide db I will analyse. Could all the code be in one event?
    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.

  6. #6
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    as soon as the database load you just try to enter the Delivery date without selection Department and Location.
    then see what happening.
    I want it as I mentioned in post no. 1.

  7. #7
    DatabaseMakers is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    London
    Posts
    12
    On the Order form not the subform add this:

    Private Sub Form_Current()
    If Me.NewRecord = True Then
    Me.DELIVERIES_Subform.Enabled = False
    Else
    Me.DELIVERIES_Subform.Enabled = True
    End If
    End Sub

    ...and the beforeinsert issue only happens when orderid is null which should be solved with the code above!~)

  8. #8
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    Thanks.
    It working.
    This Problem solved.
    But I want to add error handler to this before insert issue.
    Please tell me what will be procedure for this?

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    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.

  10. #10
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    I will check.Thanks

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

Similar Threads

  1. Replies: 7
    Last Post: 10-01-2012, 07:59 AM
  2. Replies: 1
    Last Post: 06-22-2012, 03:33 PM
  3. Conditional Combo Boxes on a form
    By ThebigCt in forum Access
    Replies: 1
    Last Post: 02-06-2012, 08:08 PM
  4. Conditional formatting on form
    By ngruson in forum Forms
    Replies: 11
    Last Post: 09-17-2010, 12:15 PM
  5. Conditional Responses in Form
    By jheintz57 in forum Forms
    Replies: 7
    Last Post: 03-31-2010, 09:57 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