PDA

View Full Version : Setting a form value to another form value and saving to the underlying table



nathan2314
01-13-2009, 09:08 AM
Hi All :hi:
I'm very new to VBA in Access. Basically all I want to do is set a text field in a form I have to a value based on another field in the form and then have that put in the underlying table.
So far I have a table created called 'OverseasConnections'. In this table, among other fields, I have two fields called 'Location' and 'Trigraph'. The field Location is linked to a table (called 'Countries') that has two fields. One is the country name and the other is the associated trigraph (for example: United States, USA etc..). The trigraph (ex USA..) is the primary key in this table. So in my form, the user can select from a drop down combo (labeled 'Location') to pick the country of interest. I would like the 'Trigraph' text box to automatically populate with the correspoding trigraph value. So if the user picked 'United States' from the 'Location' combo box, the 'Trigraph' text box should populate with 'USA'.
I built a query called qryTrigraph that uses the tables 'OverseasConnections' and 'Countries' and I pull in the values Countries.Trigraph and OverseasConnections.Location. I'm thinking if I somehow use VBA in the events section of the properties in the combo box 'Location' I should be able to automatically run this query and put the value in the 'Trigraph' text box. But I cant get it to work.
Appreciate any help!! :bow:
I know there are probably better ways of doing this.

OBP
01-13-2009, 09:35 AM
The easiest way is to place
me.Trigraph = me.combo.column(1)
in the After update event procedure of the Combo box.
Assuming that Trigraph is where you want the data to go, combo is actually your Combo Box Name and your Trigraph Column in the Combo is the second one.

nathan2314
01-13-2009, 10:01 AM
Thanks for the input.
I tried it but probably am not doing it right. I put
Me.trigraph = Me.Location.trigraph
as a EventProcedure in the 'AfterUpdate' property of the combo box (which is called 'Location'.
But when I get to Me.trigraph = Me.Location. the VBA code gives a drop down box for me to select other properties like 'ColumnCounts', 'ColumnHeads' etc etc..
If i just put Me.trigraph = Me.Location.trigraph and try to run it, it gives me a 'Method not found' error
??

OBP
01-13-2009, 10:12 AM
Doesn't it show Me.Location. column as an option at this point?
Or is there only 1 column in your combo?
if there is only one column you need to add the "Trigraph" to the combo.

nathan2314
01-13-2009, 11:05 AM
Hey Thanks! :thumb
Ya your right. It worked. I was just doing it wrong.