Sending string variable to table from form (vba)
Traditionally I would set them up using the wizard, and use the basic objects from the toolbar corresponding to the fields in my table.
But I wanted to update the way a field is entered. I have a combo box that has 3 choices for a prefix (25,45,95), then the user types in a text box to enter a 8 digit number.When the user leaves the text field, the prefix and the number entered into the text box are combined using a global string variable.
The trouble I'm having is coding the 'add record' button to transfer the variable into my table.
The pseudo code would be:
[Add button clicked event.
(string variable), and All other fields in form to corresponding fields in table-(string variable) to specific field in table]
Thank you for taking the time to report an issue.
What's wrong... Please write below.
My Ms Access application has 2 forms viz:
a) The Main form
b) A popup form
The Main form calls the popup form via a button click. The popup form has a combo box whose value is stored in a global string variable.
I want to reference this string variable from the Main form (with the popup form still running i.e popup.visible = false
The following is the post.
Const Value1 as long = 5
Const Value2 as long = 12
Const Value3 as long = 7
For I = 1 to 3
MsgBox Value & I '<-- How to do this properly?
I want MsgBox to display 5 then 12 then 7 rather than Value1 then Value2 then Value3
I can't figgure out how to get Value and I to combine properly to do this
I have a VBA class module that loads a single record from 1 of 4 tables (via a main form and datasheet subforms) to another form.
Most of the fields are keys however 1 field is memo data type.
What data type is best to use for the variable / property procedure in the class module. String seems to work but are there any limits in string length in vba, or a better way of achieving this. I seem to remember reading somewhere that memo datatype fields the data is not stored in the access db only a reference, is there any way of using this and passing the reference to the text box
Also the data is passed to the form via an ADO recordset am I right in saying that there is no issue with string length in ADO recordsets
Relevant code follows but first some things ive already tried. saved the whole thing as a string variable and used docmd.runsql. ive used quotes around field name and datatype. im stuck on this one
I have a field in this same table that shows a department value for each record. That fieldname is “Dept”.
Within a huge VBA function module I’m writing, I have a string variable assigned to the Query field called strQuery. I also have string variable assigned to the Dept field called strDept.
The query that is assigned to the variable strQuery is designed to return ALL results for ALL departments. However, I want the VBA to run the query and return results for only the department that are assigned to the variable strDept.
If I leave out the department limitation, it works fine with the following code:
I have trouble finding how to use SELECT statements within VBA in a simple context as mine surley is. The fact is, the table contains the names of every checkbox in a form, I want VBA to get those names from the table, see if they = TRUE, and then APPEND to a new table (which, thankfully docmd.runSQL works for). It just seems much cleaner than having to pour in sixty control names into the VBA code.
I've heard about using querydefs but they seem way outside the scope of my application, which is small
However I want to run this query maybe 10 times with different fixed parameters. I.e. wherecustomers is :
So I want to store some variable at some place in the vba or access that I can afterwards collect that variable again when I rerun my code.
Only way I know is to add it into a table, but is there some other, easier way?
I can refer to a field by a string but can't get a string to be used aa a variable.
Heres what I have
rs.Fields(vField.name) = "a" & Replace(vField.name, " ","")
I know the first part works (before =) as I have tried just putting any value in the table and it works fine.
obviously the second part doesn't work but hope its clear what I'm after.
my variable name is 'aName' for example and my field would be 'Name'.
The reason I need this is so that I can look through all the field names and pull the correct data from the same named variable (with 'a' prefix