Choose Function

  • Thread starter Thread starter JimP
  • Start date Start date
J

JimP

The "Choose" function in a query grid will allow you to select a field name
e.g.

Col1 = Choose (ColOpt, [Field1], [Field2].....)

Can this be done in a VBA function?
 
Choose is a VBA function, so yes, it will work in VBA.

Did you try? If so, did you have a problem with it? If so, what was the
problem?
 
This is the code:

Function SelectCol(ColOpt as Integer)
SelectCol = Choose(ColOpt, [Field1}, [ Field2].......)
End Function

This is the same code that works in a query grid but returns an error in a
module - "External name not defined". I believe it has to do with the
brackets.


Douglas J. Steele said:
Choose is a VBA function, so yes, it will work in VBA.

Did you try? If so, did you have a problem with it? If so, what was the
problem?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


JimP said:
The "Choose" function in a query grid will allow you to select a field
name e.g.

Col1 = Choose (ColOpt, [Field1], [Field2].....)

Can this be done in a VBA function?
 
What are you expecting it to do?

Ignoring the mistyped }, VBA knows nothing about [Field1], [Field2], etc.:
that's how you refer to fields in a table in a query.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


JimP said:
This is the code:

Function SelectCol(ColOpt as Integer)
SelectCol = Choose(ColOpt, [Field1}, [ Field2].......)
End Function

This is the same code that works in a query grid but returns an error in a
module - "External name not defined". I believe it has to do with the
brackets.


Douglas J. Steele said:
Choose is a VBA function, so yes, it will work in VBA.

Did you try? If so, did you have a problem with it? If so, what was the
problem?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


JimP said:
The "Choose" function in a query grid will allow you to select a field
name e.g.

Col1 = Choose (ColOpt, [Field1], [Field2].....)

Can this be done in a VBA function?
 
It's probably just as easy (or easier) to place the "Choose" function in the
query grid for each column. I was hoping to re-use the code for multiple
columns.



Douglas J. Steele said:
What are you expecting it to do?

Ignoring the mistyped }, VBA knows nothing about [Field1], [Field2], etc.:
that's how you refer to fields in a table in a query.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


JimP said:
This is the code:

Function SelectCol(ColOpt as Integer)
SelectCol = Choose(ColOpt, [Field1}, [ Field2].......)
End Function

This is the same code that works in a query grid but returns an error in
a module - "External name not defined". I believe it has to do with the
brackets.


Douglas J. Steele said:
Choose is a VBA function, so yes, it will work in VBA.

Did you try? If so, did you have a problem with it? If so, what was the
problem?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


The "Choose" function in a query grid will allow you to select a field
name e.g.

Col1 = Choose (ColOpt, [Field1], [Field2].....)

Can this be done in a VBA function?
 
Back
Top