Results 1 to 14 of 14
  1. #1
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162

    Enable or disable a form field based on a Check box in the form.

    In my BOUND access form I have [Tolerance] check box, [Tolerance%] box, [LC value] box and [LCA value] box. First one is a check box, second one is integer and rest of the two are currency.


    I'd like a code that if finds the [Tolerance] check box UNCHECKED, will make [LCA value] box blank and Disable for editing or adding value. And i f found CHECKED, will Enable [L CA value] box and in it put the result of {[LC value] box value * ([Tolerance%] box value + 100)/100}. Thanks in advance.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Code:
    txtLCA.locked =not chkTolerence.value 
    
    if chkTolerence.value 
        txtLCA =  box value * txtTolerancePct
    else
        txtLCA = ""
    end if

  3. #3
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Dear ranman256,
    I guess the code goes to the form's module. But could you tell me, again What Event do I need to put this code. I tried this as it is (of course after adjusting the field names and formula) in the VBE but it didn't work. Please help.

  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,633
    Try the checkbox Change event as well as the form Current 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.

  5. #5
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Do i have to put the same code against both events? There is no checkbox Change event. Then what event? I've put the following code in the form Current event:
    Code:
    Private Sub Form_Current()
    [LCA Amount].Locked = Not Tolerance.Value
    If Tolerance.Value Then
    [LCA Amount] = [LC/TT Amount] * ((100 + Tolerance%) / 100)
    Else
    [LCA Amount] = ""
    End If
    End Sub
    Then it shows the error: "Type-declaration character does not match declared data type" and highlight Tolerance%(blue). What gives?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Sorry, guess it would be the checkbox Click event. Code in both events or in a Sub behind the form that can be called by both events.

    You show Tolerance and Tolerance%. Is one the textbox name and the other the field name?

    % is a special character.

    Should avoid spaces and special characters/punctuation (underscore is exception) in naming convention, otherwise always enclose in []: [Tolerance%].

    Better name would be TolerancePct or Tolerance_Pct.
    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.

  7. #7
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    I've used [Tolerance%] and for the first-time i worked. But as i've closed the form and open it again, it showed "Run-time error '94' Invalid use of Null" and highlighted the line: "[LCA Amount].Locked = Not Tolerance.Value" in yellow.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    The checkbox is bound to a Yes/No type field?
    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.

  9. #9
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Yes it is bound to a Yes/No data type field of the table and in On/Off format.

  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,633
    That is odd. The field should never be Null, must be either Yes or No (True or False, -1 or 0).

    I can't replicate the issue. If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  11. #11
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Whenver I try to add new record to the form the Tolerance checkbox is neither checked nor unchecked, it becomed blue filled. I couldn't find a -1 or 0 option, can you tell me how to get them. I have changed the On/off format to True/false, still it shows the same error. This time i am attaching the database for your checking. Please remove the .zip file extension which i have renamed myself as the server didn't let me attach a .rar file which actually it is. LCorTT.rar.zip

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    I cannot open rar files, only Windows Compression zip files.
    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.

  13. #13
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Please find the file in windows compression zip format.LCorTT.zip

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Normally a form can enter/edit data for only one table. You have the form bound to a query that includes both Order and Shipment tables with in an INNER JOIN. INNER JOIN requires related records in both tables for record to display in query. This form will not work. Should use a form/subform arrangement.

    Naming convention will cause frustrations. Suggest you change.
    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: 9
    Last Post: 05-04-2014, 04:26 PM
  2. Replies: 4
    Last Post: 03-05-2013, 09:03 AM
  3. Password Form With Enable/Disable Shift Key
    By burrina in forum Code Repository
    Replies: 0
    Last Post: 12-24-2012, 10:53 PM
  4. Replies: 1
    Last Post: 02-25-2011, 10:03 AM
  5. Replies: 3
    Last Post: 09-29-2010, 09:31 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