Results 1 to 6 of 6
  1. #1
    hwest is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2018
    Posts
    2

    Help Request: Using CheckBox to Dynamically Add text to a field...

    Greetings Forum-goers.

    I'm new to the forums and new to using ACCESS in general. I've gotten good at snipping and reformatting Excel formulas to get what I want, but I'm finding Access is a whole new beast, and I'm not nearly well acquainted enough with VBA to just slap things together.

    I've been attempting to created a database, forms, and reports based on a simple Excel system I've been using and I've run into the first of many roadblocks I am sure I won't be able to solve, so here we be.

    I'm using Check Boxes to indicate whether or not a certain service/testing is required. I used the formula =IIf([CLAUSES] Like "*PH*",True,False) to cause the check box to be checked if the value "PH" is in the CLAUSES field. This worked fine in the CONTROL SOURCE, however I cannot figure out how to reverse that so that if the check box is checked in the form, "PH" will be entered into the table when entering new records. I've searched to no avail, and though I'm sure I ran across something that was close to the answer I wasn't able to make it work. Having what I have in the CONTROL SOURCE causes the checkbox to be locked in new records, since it's dependent upon the text in the field.

    A few important notes: The CLAUSES field in question will have multiple letter codes (PH for physical testing, DI for dimensional verififcation, RT for X-ray, etc.. I was separating these using commas, though that isn't critical... I've created multiple checkboxes, one for each required test/service, which should each check the CLAUSES field for its letter code, or enter its specific code into the field for new records... the checking part works fine as mentioned above, but the reverse of it is a no go so far.)



    Thank you in advance for any help you may be able to provide.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Welcome to the forum.
    You're right --Access is not Excel. Different products for different purposes and audiences. Built upon different object models.

    You have focused on a detail -- IIf statement--, but what is the application in overview.

  3. #3
    hwest is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2018
    Posts
    2
    Thank you for a quick reply, I'm not sure what you're asking though? I'm working in MS ACCESS 2016. The object I'm trying to create will be a form used to create new records on a table which will be the master log of information, that will be pulled to other forms/reports. The -- IIf -- Statement is what I was using in Control Source of the Check Box, however it only reads information from the field in the table from old records, I can't figure out how to have the field populated when the check box is clicked on a new record.

    The overview of the project in question is as a master database to be used for populating information dynamically in various forms and reports across our operation.

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    As you've discovered, you can't change the value of a textbox control via the click event if the control has a calculation in the Control Source. Remove those calculations.
    Have a bound Yes/No field in the table for each checkbox, bound to the form checkboxes. Then in the form code:
    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub Clauses_AfterUpdate()
        If Clauses.Text Like "*PH*" Then
            chkPH = True
        Else
            chkPH = False
        End If
        If Clauses.Text Like "*DI*" Then
            chkDI = True
        Else
            chkDI = False
        End If
        If Clauses.Text Like "*RT*" Then
            chkRT = True
        Else
            chkRT = False
        End If
    End Sub
    When the clauses textbox is changed, this code will run and set the checkboxes.
    Last edited by davegri; 12-21-2018 at 12:41 PM. Reason: format

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Hi hwest and welcome!
    In the AfterUpdate event of your checkboxes you need to add code similar to this (in this example the check box for the PH text is named chkPH and the Clauses text box is named txtClauses):

    Code:
    Private Sub chkPH_AfterUpdate()
    if me.chkPH=True
    .need to add PH if not present
        if instr(me.txtClauses,"PH")=0 then me.txtClauses=Trim("PH," & me.txtClauses)
    else
    'need to remove PH if present
     if instr(me.txtClauses,"PH")>0 then me.txtClauses=Trim(replace(me.txtClauses,"PH","")
    end if
    'clean up extra commas
    me.txtClauses=trim(replace(me.txtClauses,",,",","))
    if left(me.txtClauses,1)="," then me.txtClauses=mid(me.txtClauses,2)
    if right(me.txtClauses,1)="," then me.txtClauses=left(me.txtClauses,len(me.txtClauses-1))
    Cheers,
    Vlad

  6. #6
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    New approach, have a look at this. No bound fields for the checkboxes needed in the table. Actually, checkboxes changed to radio buttons in a frame so that only one can be checked at a time.
    If isn't clear where (what field) you want the PH, DI, or RT to appear in the updated table.
    Also, if Clauses contains DIRT, which is it, DI or RT?
    hwest-davegri-v01.accdb

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

Similar Threads

  1. Replies: 7
    Last Post: 03-02-2014, 03:16 PM
  2. Replies: 7
    Last Post: 01-22-2014, 01:09 PM
  3. Using A Checkbox For A Text Field
    By LanieB in forum Forms
    Replies: 1
    Last Post: 04-12-2013, 06:18 AM
  4. Function to Dynamically Parse Text
    By avandalay in forum Access
    Replies: 2
    Last Post: 07-27-2011, 04:07 PM
  5. How to validate dynamically generated text box
    By TheFuzzball in forum Forms
    Replies: 1
    Last Post: 10-24-2009, 10:49 AM

Tags for this Thread

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