Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can somebody help with this? I a 1

Status
Not open for further replies.

JDRoss

MIS
Sep 27, 2002
67
IE
Can somebody help with this?

I am trying to update a value on a form's combobox from an not in list event.

I am making some error with the referencing of the control because this doesn't find the control

Code:
Forms(frmname)!frmcmbtrl.Column(1).Value = strnewvalue

I want to be able to pass the form name and controls dynamically at run time

Appreciate any help

John
 
Hi

I noticed that you missed a '!'
Should be

Forms!myform!mycontrol.column(1).Value = strnewvalue

This could be a typo, let me know

Nowell
 
JDRoss,

You seem to be mixing two reference methods...

One method uses:
Forms("FormName")("ControlName").PropertyName

The other uses:
Forms![FormsName]![ControlName].PropertyName

Each has its place, in my opinion....when using variables to do things, I use the Forms("")("") becuase I find it easier to reference. But when just refering to exact controls and properties I genrally use the Forms![]![] method.

I also don't think you need the .Value after .column(1)....I have never seen this used. By default, if you say:
Forms![FormName]![ControlName]
Access will automatically give you the .Value property. For ComboBoxes this is column 0...of the first column as columns begin at zero. But you can change the property you want by using the:
Forms![FormName]![ControlName].PropertyName
And in the case of ComboBoxes, .column(1) means provide the value of field 2, .column(2) is for the value in field 3, and so on...

****************************
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Thanks mstrmage1768 for your expert help and advice on referencing forms and controls this way. Am I right in saying that the one with the "()" brackets is implicit referencing and the other form with the square "[]" brackets is explicit? I was trying to find this described in the Access Handbook but could not find the right word.

Anyway, this worked perfectly.

Code:
Forms(frmname)(frmcmbtrl) = strnewvalue

This also worked for requerying the combo's record source

Code:
Forms(frmname)(frmcmbtrl).RowSource = Forms(frmname)(frmcmbtrl).RowSource

Could I suggest that you post your logic and understanding as a faq because it makes perfect sense and is very helpful.

Regards and thanks once again

John

 
I don't think there's technically a syntax problem mixing the different methods of referencing objects. For instance:

Code:
Forms("frmName")!ctrlName

...should work just as well as:

Code:
Forms("frmName")("ctrlName")

...or:

Code:
Forms!frmName!ctrlName

There may be small speed differences in the different methods of referencing objects. But I do agree that for debugging and readability it's a good idea not to mix and match.

I believe the problem in John's original post is that the Column property is a read-only property.

HTH,

Ken S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top