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

    VBA to update a complete field.

    Can someone confirm. If an unbounded text field is placed on a form, can it keep the info when closed and open again?

    I use Update queries and it works, but I prefer to have the VBA. Below follow detail of my situation. If someone can help me with the VBA code.
    a. The field is in query q01AssetsTypes.
    b. The fieldname is "PrefixA".
    c. There is an unbounded text field on the form f01AssetsTypes named txtPrefix.

    I want on "After update", or "click" on the form txtPrefix to update the field PrefixA for the input to display the code for every record.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,906
    Why unbound?
    Just have it bound and disable it?
    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
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    I use a Prefix on every form to go in front of the number. Yes , I know to put it in the format space in the table, but I respect your time. My app has got more than 250 tables. The prefix consists of three letters. No Prefix for any form's numbers may be the same. I want to be able to change it even if it almost never change, then it must update the query. I have a successful way to do it with an update query, but I do not want to create 250 Update queries. I would like to be helped with the VBA.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,778
    Maybe
    CurrentDb.Execute "UPDATE q01AssetTypes SET q01AssetTypes.PrefixA = '" & Forms!f01AssetsTypes.txtPrefix & "'"

    Note that since there is no criteria there, all records will get that value, which may or may not be what you want:
    display the code for every record.
    It also assumes that the textbox value is a string and not a date. The form would have to be open and a value must be in the unbound control. I strongly suggest you do not run record modifying code that you are given on your real data - copy the table or db and play with the copy.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    Fantastic, thank you. Yes that was exactly what I want, and works correct. I thought I can solve the next part myself, but no. On the images things can be seen.

    a. RecordCodeC is a calculated field in the local table and query. Calculation is PrefixA & "" & AssetsTypesNumber.
    b. RecordCodeA is a field in a linked query named q01CombinedEntities, most of my queries link to q01CombinedEntities.
    c. I want RecordCodeA to equal RecordCodeC after the same event. After your line.
    d. You may see following your advice I tried the same code in the last line of my image.
    e. The result in RecordCodeA is a 7 after every Prefix? The 7th record was open during activation.

    What am I missing?
    Click image for larger version. 

Name:	220727a.png 
Views:	24 
Size:	17.8 KB 
ID:	48383Click image for larger version. 

Name:	220727b.png 
Views:	23 
Size:	16.3 KB 
ID:	48384

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,778
    Sorry I haven't had time to get back to this over the last little while. If the real problem with your last post is item e, then if you review my solution you'll see that I said that whatever you apply as an update would happen to every record if you didn't apply criteria. Your afterupdate code does not apply any criteria. I cannot tell which of those query fields you might want to apply criteria to. Perhaps 1, 2 or 4, or some combination of the 3 fields.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Update bound textbox after notinlist event complete
    By ZdenniZ in forum Programming
    Replies: 15
    Last Post: 09-01-2019, 08:54 PM
  2. Button to complete a field and save record
    By Davince in forum Forms
    Replies: 4
    Last Post: 01-25-2015, 07:22 AM
  3. Replies: 1
    Last Post: 02-26-2014, 03:19 PM
  4. Replies: 5
    Last Post: 10-24-2013, 04:17 PM
  5. Auto complete field on form
    By oam in forum Access
    Replies: 5
    Last Post: 09-23-2011, 12:45 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