I'm trying to build a sub procedure to create a list for a combobox. Basically, the db has sererate fields in the client table for first and last names and I want to create a combobox that lists each in one line. The real point of the question is whether or not I can build a sub procedure so I can call that procedure (create the list) at any time without having to write it over and over again.

Below is the call from the forms sub procedure, where 'ListGenerators' is the module name, 'CreateContactsCombo' is the sub name, and the arguments are the Form name and existing comboboxes to be used to build the contacts list. (i.e. the results from cboFirstName and cboLastName are combined to create a list of full names in cboContactName)

The message boxes in this code are for information only...to see if the byRef variables are being brought into the procedure correctly...which they seem to be. I'm running into an issue with the first line after the message boxes. With frmName!cboLast.ListCount I get a runtime error '2645': "can't find the field 'cboLast' referred to in your expression. I don't understand this considering "MsgBox cboLast.Name" give me the correct reference of "cboLastName".

I've also tried to us define frmName as string, and my code read "Forms(frmName).cboLast.ListCount". When using this I get the error "Application-defined or object-defined error"

I'm kind of playing here. I can write the code into the forms procedure without using a call to another procedure, but I thought it would be nice to use a seperate sub. I may want to call it from other procedures in the future, might make my code less "cleaner", and save me some time.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy

Processing your response...

Discuss This Question: 5 &nbspReplies

There was an error processing your information. Please try again later.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy

I have never worked with access, but it seems to me that your message boxes are not helping at all, because you are displaying information from the combos the procedure receives as parameters, but in the rest of your code you are not using them.
In other words, inside the procedure:
frmName!cboLast <> cboLast
If you are going to use the combos this way (in the case that that is possible, which I don't really know) inside the procedure:
frmName!cboLast
Then you should not need to send them as parameters to the procedure (and vice versa).

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy

Processing your reply...

Ask a Question

Free Guide: Managing storage for virtual environments

Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!

To follow this tag...

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy