I am trying to create VBA code that stores values in a table called 1_GlobalVariables, then more code--tied to a different form--that retrieves these values for further actions. The specific goal at the moment is a command button next to a combobox that will take the user to a detailed 'add new' form and then simply pop the new ID into the combobox when the new record is saved. This sort of thing was requested in one of my other projects here (it was thought unreasonable to have to manually select the new record after just having created it, which is a fair point, as it should be the default) and I would expect to use it all the time.
Here's my first effort as it stands:
Expand|Select|Wrap|Line Numbers
- ' First, note where the new name should be added.
- Dim stSQL As String
- Dim stGlobalValue As String
- Dim stGlobalType As String
- DoCmd.SetWarnings False
- stGlobalValue = "Forms!frm3ViewEditAddProperties"
- stGlobalType = "LocationForm"
- stSQL = "UPDATE 1_GlobalVariables "
- stSQL = stSQL & "SET GlobalValue = '" & stGlobalValue & "' "
- stSQL = stSQL & "WHERE GlobalType = '" & stGlobalType & "';"
- DoCmd.RunSQL stSQL
- stGlobalValue = "cboMgtIndex"
- stGlobalType = "LocationControl"
- stSQL = "UPDATE 1_GlobalVariables "
- stSQL = stSQL & "SET GlobalValue = '" & stGlobalValue & "' "
- stSQL = stSQL & "WHERE GlobalType = '" & stGlobalType & "';"
- DoCmd.RunSQL stSQL
- DoCmd.SetWarnings True
If I can get this to work, I'll expand it to include the most recently viewed record for a form, the form last in use, possibly tied to the user, etc, with an eye to facilitating the data entry and management.
Sorry to have to post this as a new question, as I'm sure it's been addressed before, but somehow I'm having trouble finding anything I can use; links to relevant threads would be absolutely brilliant to get me started. I thought I'd seen an approach like this described somewhere, but can't track it down again. And any results for web searches like 'microsoft access global variables' are way over my head at this point. But since information is so hard to find, I wonder if I am attempting a method that doesn't work well with Access.
Am I going about this the right way, and if so, what next?