Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

How to add a text field (seemingly) to a complex select query.

My user wants to add a read-write row level field to a form backed by a complex select query where all existing tables are read-only. I can add a new table to the database with the necessary key fields to link it to the rows of select query, but I would like some guidance with the best approach including the methods to add the record and update fields. My VBA experience is mostly with Excel, but have written several simple Access applications.

I would like the field to appear in the form as if the field is always present even though it is not. I understand I will have to requery the form data and the user will experience some screen flashing.
  • 2
2 Solutions
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Complex select queries are rarely updateable, so if the current query is NOT updatedable, then adding another table won't help matters - and you cannot identify specific Tables/Fields in your Query that should be updateable, while leaving others as non-updateable.

If you can make the query updateable, then you could simply set the Form Controls (i.e. the textboxes, dropdowns, etc) to Enabled = True and Locked = False. This would stop user from modifying those fields, and you could leave your new field as a read/write value.

As I mentioned earlier, however, this all depends on if you can make that complex query updateable ...

If you like, you could use SQL/VBA to handle this, perhaps in the AfterUpdate event of your textbox. Something like this:

Sub MyControl_AfterUpdate()
  Currentdb.Execute "UPDATE SomeTable SET SomeField='" & Me.MyControl & "' WHERE IDField=" & YourIDValue
End Sub

Obviously, you'd have to change the names of Tables and Fields to match those in your database.
Armen Stein - Microsoft Access MVP since 2006PresidentCommented:
Or, you could put the one updatable field in a tiny subform that's related to the main form using Master/Child properties.

Armen Stein
WilbertWaterburyAuthor Commented:
Thank you both @ScottMcDaniel and @ArmenStein. I am considering both of your comments and will respond shortly.
WilbertWaterburyAuthor Commented:
@Scott's UPDATE command was the ticket (plus an add record if one did not already exist) and was a huge help thanks to you both for your ideas!

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now