Results 1 to 6 of 6
  1. #1
    MF_PA is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2024
    Location
    Italy
    Posts
    11

    field update failed in form current event

    Hi,
    using my VBA instructions I cannot update the value of the text box "Txt_Obtained" with the real time results of my combo box .


    The result of this text box during the form current event is updated according to what is typed in other text boxes and depending on some option buttons of the same form, obtaining a similar result (which will be used to set the form filter)


    example:
    MyVar & [city] Like '" & Me.Cmbx1city.Value & "'And [code] Like '" & Me.Cmbxcode.value & "'And [enterprise] Like '" & Me.TxtEnterpriseChosen & Chr(39)


    During the form_current event ,when I update text boxes or option buttons, immediately are updated MyVar and TxtEnterpriseChosen . Consequently, "Txt_Obtained" is updated, using the value already present in the two comboboxes Cmbx1city and Cmbxcode.




    Here's my problem, the result of the Txt_Obtained check is correct only if I first change the value of one of the two comboboxes, and then I change that of the text boxes or option buttoms.
    Instead, if first I change that of the text boxes or option buttoms and in a second moment I change the value of one of the two comboboxes, the Txt_Obtained control is not updated to the new value selected in the combobox.




    I've also tried (whith no results) to insert VBA instructions into the Cmbx1city _AfterUpdate() and Cmbxcode _AfterUpdate() events.


    Thank you for your clarifications

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Create a function in the form to concatenate your control values.
    Then call that from various events of the controls that hold those values.

    Either AfterUpdate or even Lost Focus events.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Lack of space in front of And in "'AND could be an issue. And LIKE without wildcard might as well just be = sign.

    But exactly where is this expression used? Provide code or db for analysis.
    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.

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    is this an sql statement? The LIKE has no *
    each combo box (or any control) must rebuild the filter in the AFTERUPATE event.


    Code:
    sub Cmbx1city_afterupdate
    UpdBox
    end sub
    
    
    sub Cmbxcode_afterupdate
    UpdBox
    end sub
    
    
    sub TxtEnterpriseChosen _afterupdate
    UpdBox
    end sub
    
    sub UpdBox()
      'exact = statement
    me.filter  = "[city] = '" & Me.Cmbx1city & "' And [fieldcode] = '" & Me.Cmbxcode & "'And [enterprise] = '" & Me.TxtEnterpriseChosen & "'"
    me.filterON = true
    end sub

  5. #5
    MF_PA is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2024
    Location
    Italy
    Posts
    11
    Quote Originally Posted by June7 View Post
    Lack of space in front of And in "'AND could be an issue. And LIKE without wildcard might as well just be = sign.
    The code obtained appears to work at least until I use the comboboxes, which instead are read correctly when I then act on the text boxes or on the option button.

    Thats why I believe it does not depend on this code. So I am currently making various attempts, by following the suggestions of the other two members ( to use my code whith the After update event).

    if I don't find a solution for the next few days, i'll Provide a part of db for analysis


    PS: I confirm that my code is used to obtain a SQL statement. the reason that complicates my code is that the filter uses MyVar which is the result of the checks on the text boxes or on the option button

    Thanks

  6. #6
    MF_PA is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2024
    Location
    Italy
    Posts
    11
    Solved!For each my combo box (and my others controls) I’ve rebuilt the filter in the AFTERUPATE event.
    It didn't work because my instructions in vba AFTERUPATE event, did not correspond with the secting properties of the two cmbx ( not yet selected) . Thats why, originally, the cmbx had been copied from another form.

    Thank you all

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

Similar Threads

  1. Replies: 13
    Last Post: 12-20-2017, 08:35 PM
  2. Replies: 1
    Last Post: 05-06-2015, 04:28 AM
  3. Replies: 3
    Last Post: 01-14-2015, 02:51 PM
  4. Replies: 7
    Last Post: 05-08-2014, 10:34 AM
  5. Failed to update all field
    By somya123 in forum Queries
    Replies: 0
    Last Post: 01-30-2009, 12:52 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