Results 1 to 5 of 5
  1. #1
    Perfac's Avatar
    Perfac is offline Expert
    Windows 7 64bit Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618

    VBA code to fill field.

    I have a query q01Bankbranch and form f02BankBranch. There is a checkbox named Check02. There is a field LdgAcc_ID01. This field is from another table, and shared by 6 other tables. I assume I can't do an expression, so I need VBA code. I want the field LdgAcc01_ID01 to return If Check02 is True then 77 otherwise 80. I tried



    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Me!LdgAcc_ID01 = IIf(Check02.Value = True, 77, 80)
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You tried that and...what? Incorrect result, error message, etc? Are both of those controls/fields on the form, and is the form updateable?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Agreed, more info. But...
    if you open a form that has checkboxes and one of them appears to be filled (black in 2016, blue in earlier versions) then open the vb editor. In the immediate pane, type
    ?forms!NameOfYourForm.NameOfYourCheckbox and hit return (this is for the filled checkbox, no other). Your result should be Null. In that case, it is neither True or False. This seems to be the case even if the triple state property of the check is False. Hate to admit, but not sure why. Will have to read up on it.

    Anyway, point being that assuming no issue as described by Paul, that could be your problem. If so, wrap the expression in Nz, or handle the null some other way.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Perfac's Avatar
    Perfac is offline Expert
    Windows 7 64bit Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    Hi. Sorry that code is working.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'd be happy it's working, not sorry.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 5
    Last Post: 11-27-2017, 07:09 AM
  2. Replies: 1
    Last Post: 02-26-2015, 07:45 PM
  3. Replies: 2
    Last Post: 02-05-2015, 02:50 PM
  4. Replies: 2
    Last Post: 11-30-2014, 07:52 AM
  5. Replies: 5
    Last Post: 01-20-2011, 11:36 PM

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