473,224 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

Use field name as a parameter in a subroutine or function

I have an application with many combobox in different forms used for
choose a particular length (for example items are "ft" - feet, "in" -
inch, "m" - meters, and so on).
I don't want to put in every form (class), in load event, the code
needed to load items from a Db table using items.add.
I want to create a public subroutine (or function), when i call it I
pass, as a parameters, the form and field name, then the subroutine
read from the table and add items in the form/field I have passed as
parameters.
I don't know if I can do that and how.
Any suggestion?

Nov 9 '07 #1
1 2150
On Nov 9, 9:51 am, bassi.ca...@gmail.com wrote:
I have an application with many combobox in different forms used for
choose a particular length (for example items are "ft" - feet, "in" -
inch, "m" - meters, and so on).
I don't want to put in every form (class), in load event, the code
needed to load items from a Db table using items.add.
I want to create a public subroutine (or function), when i call it I
pass, as a parameters, the form and field name, then the subroutine
read from the table and add items in the form/field I have passed as
parameters.
I don't know if I can do that and how.
Any suggestion?
Your function should be in a module and probably look like this:

Public Sub AddItemsToComboBox(byref combo as ComboBox,byval field as
String,byval table as String)
combo.items.clear()

'get the records from the database
combo.items.add(field & " from function")
combo.items.add("another record")

end sub

and then you can call it like this:

public sub form_load(...)

AddItemsToComboBox(ComboBox1,"fieldname","tablenam e")

end sub

That's all you should need to do. Adapt this as you need it :-)

Phill

Nov 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hon Seng Phuah | last post by:
Hi, I am quite new to perl development and have a question very stupid question. I hope that someone can help me. Does perl support in/out parameter subroutine? Like in C/C++, we have a...
5
by: j_liu21 | last post by:
Is something like this possible? A form with x fields named field1, field2, ... fieldx I'd like to set the field specified in the parameter function SetUnknownField(FieldID) {...
18
by: NickName | last post by:
The following example may further clarify the question, Select fieldA, filedB, fieldC >From tblX Where fieldD = Forms!formName!controlName What I'd like to know is how to determine or get...
6
by: Jeff Frederick | last post by:
Hello all, I am interested in using the value from a field to call a function. For example I have a table and one of the field names is "Function." So for each record I input the name of the...
3
by: vipul DotNet | last post by:
hi friend, I have a function which can accept 2 parameters , one as any double value second as "Y" or "N" public sub abc(byval dblvalue as double,byval strvalue as string) end sub I want...
2
by: Richard | last post by:
Hi. How can I pass a subroutine as a parameter to another subroutine? How would the formal parameter list needs to be declared in order to receive a rubroutine (address)? Thanks in advance, ...
7
by: Richard Grant | last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter How do I do that in VB .NET What should be the syntax for a parameter to receive the address of a...
2
by: K B | last post by:
Hi, Is there ANY WAY to hide a row/field in a DetailsView based on meeting a condition at the ItemCreated or ModeChanging event -- or any other way? There appears not to be, but I was hoping for...
4
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.