temporarily remove fields from form

Posted on 2012-09-04
Last Modified: 2012-09-06
I use a mail merg utility to create word documents. This utility will place a bookmark froma field on the form onto the word document that it creates.

The form contains:
exam address
exam city
exam state

shipping address
shippin city
shipping state

an option box that allows the user to select exam or shipping address to be different.  So I want the shipping address ect... to be the same as exam address unless the user selects the option box to specify a different shipping address. How would I do this?
Question by:seamus9909
    LVL 2

    Expert Comment


    For this, you can place a check box in above of Shipping Address.

    If user select this checkbox, then exam address and shipping address are same, and using javascript, you can push up the exam details into shipping address details for automatically fillup. If is is unchecked then user should fill up the shipping address.

    Hope this will resolve your issue.
    LVL 10

    Expert Comment

    using the simple javascript
    function diffShipAddr(){
    function sameShipAddr(){

    Open in new window

    then adding onload="sameShipAddr()" to your BODY TAG
    and onClick event on the checkbox, that fires the diffShipAddr function.

    LVL 39

    Expert Comment

    Is it MS Access or something else? In Access you can fill shipping address with the same values as exam address if this checkbox is not marked.
    Afterupdate event for exam fields (exam address etc.):
    If Not Me.MyCheckBox then  Me.[shipping address] = Me.[exam address]
    LVL 56

    Expert Comment

    by:Jim Dettman (Microsoft MVP/ EE MVE)
    in addition to setting the fields the same, you might also want to hide/show the additional fields on the form depending on the state of the check box:

     Me.MyShippingAddressControl.Visible = Not Me.MyCheckBox

     So if the checkbox is true (Billing and Shipping are the same), then the shipping control should not be shown.  If it's false, then it should be and it's default value is the billing address.

     Or some variation there of.


    Author Comment

    Yes this is Access.  Will Javascript run in Access?

    Im confused.
    LVL 56

    Expert Comment

    by:Jim Dettman (Microsoft MVP/ EE MVE)
    <<Will Javascript run in Access?>>

     No.  Think it's just a matter of ienaxxx believing they were in another area.  I've dropped into SQL Server and mySQL thinking I was answering an Access question.

     When you go by keywords for spotting questions, sometimes you end up in a topic area that is different then what you think and it's easy to miss.


    Author Comment

    oh Ok that helps Jim.


    Author Comment

    sorry Im stillnot getting it.  If the user Selects the checkbox  [chkShipping] then I want the shipping address to be entered, if they dont select it the chk box then I want the ExamAddress , city state ect to fill the Shipping Address fields.
    LVL 56

    Accepted Solution

    <<orry Im stillnot getting it.  If the user Selects the checkbox  [chkShipping] then I want the shipping address to be entered, if they dont select it the chk box then I want the ExamAddress , city state ect to fill the Shipping Address fields. >>

     Well like anything, there are a number of ways to approach this.   Personally, I would show both sets of addresses, have the check box "Same as billing address" next to the shipping address and when checked, the shipping fields are set to the billing, and the shipping controls are disabled.

     The BeforeUpdate event of the form would need to ensure that all fields are filled in.

     So here's the steps:

    1. Initial form setup is that all the fields are there and are enabled.

    2. Tab order is Bill To controls first, then check box, then ship to's, then "OK" or whatever after that.

    3. As said above, for the AfterUpdate Event of the check box, you'll need to do:

       If Me.cbxCopyBillTo = True then
           Me.txtShipToName = Me.BillToName
           Me.txtShipToAddress1 = Me.txtBillToAddress1
           Me.txtShipToAddress2 = Me.txtBillToAddress2
           Me.txtShipToCity = Me.txtBillToCity
           Me.txtShipToState = Me.txtBillToState
           Me.txtShipToZip = Me.txtBillToZip

           Me.txtShipToName.Enabled = False
           Me.txtShipToAddress1.Enabled = False
           Me.txtShipToAddress2.Enabled = False
           Me.txtShipToCity.Enabled = False
           Me.txtShipToState.Enabled = False
           Me.txtShipToZip.Enabled = False
           Me.txtShipToName.Enabled = True
           Me.txtShipToAddress1.Enabled = True
           Me.txtShipToAddress2.Enabled = True
           Me.txtShipToCity.Enabled = True
           Me.txtShipToState.Enabled = True
           Me.txtShipToZip.Enabled = True
    End If

     and of course making sure that all the controls reference in the above are changed to the names of your actual controls.

      Then in the BeforeUpdate event, check whatever fields you want to ensure they have something in them.

    Let us know if you need more detail.

    LVL 39

    Expert Comment

    Jim, I think logic in yiur example is reversed. May be this will be proper sequence:
    1. Initially checkbox  [chkShipping] is false and all fields with shipping addresses are disabled.
    2. If checkbox  [chkShipping] is changed to true, all shipping fields should be enabled.
    Autoupdate sub for checkbox:
    Me.[shipping address].Enabled = Not Me.[shipping address].Enabled
    Me.[shippin city].Enabled = Not Me.shippin city].Enabled
    Me.[shipping state].Enabled = Not Me.[shipping state].Enabled

    3. In Merge button's code in first strings:
     if Me.[chkShipping] = false then
         Me.[shipping address] = Me.[exam address]
         Me.[shippin city] = Me.[exam city]
         Me.[shipping state] = Me.[exam state]
    ........ merge code
    LVL 56

    Expert Comment

    by:Jim Dettman (Microsoft MVP/ EE MVE)
    <<2. If checkbox  [chkShipping] is changed to true, all shipping fields should be enabled.>>

     Depends on how you label the checkbox:

    "Copy Bill To"
    "Use Bill To"


    "Enter shipping address info"

     and if it is true/false initially as appropriate.  I've seen this coded a bunch of different ways.  Some hide the fields, some allow you to copy the billing info, but still make changes (copy is a button rather then a check box), etc.

    LVL 10

    Expert Comment

    Yeah i was wrong thinking it was a website... sorry :-)

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now