Albert D. Kallal said:
A few things:
You are using .value and.text intermixed in your code (at least try and be
consistent in your coding practices, and even if the code is wrong, I would
much prefer that you did one thing always the same way).
In access the VBA code, you will very rarely use .text. The text is only a
valid property of control when the control has focus, and thus is of little
use in most of your daily code that you'll use.
You often see some code in this newsgroups where people are trying to read
or modify the value of a control and you'll see zillions and zillions of set
focus commands because you can not read or modify the value of a controlled
when you use the .text property *unless* it has the focus.
You would thus have to go for each time you use .text:
docmd.SetFocus cmbEmployeeName
MyClause.Add Item:=cmbEmployeeName.Text
In a nutshell using the.text property of a control is extremely messy, and
you don't need to use it on all. I suspect there is some confusing here
because in VB6 all developers use the .text property for all of their code
(that is all they have, and it's not dependent on the control having focused
to use it in visual basic)
In MS access we must use.value. So often the reason for this confusion is
many developers coming from a visual basic background instinctively and
naturally been using the text property of a control for many years.
In a nutshell using.text is extremely messy, and you don't need to use it
all. (use the .value property).
I fact in most cases you don't even have to use the .value property and can
just use the name of the control.
eg
msgbox "last name contorl is = " & LastName
Ironically one exception or one area that deserves an extra bit of caution
is when you're adding controls to a collection. You most surely want to be
very careful and distinguished between the.value property, and that of
actually adding the actual control to the collection.
The following data control can referenced on a form and display the value
msgbox "LastName value is = " & me.LastName
if you go:
MyColleciton.Add me.LastName
You'll actually not add the value of lastname to the collection, but you'll
actually add the actual control on the form or reference to the control on
the formed to your collection. That is certainly a considerable difference
in the outcome. In fact after you add that control to the collection then
you could actually use the.value property , the .height property etc of that
control from the collection. So while in using the message box command or
assigning the value of a control into a variable, for the most part you can
actually does dump the use of the .value property, however when using the
collection it is significantly important to always specify that you want the
value of the control copied into the collection, and not the actual control
added to the collection.
I shall also assume that this code you're writing is in the form's code
module, since if you put the code in a standard code module you're not be
able to distinguish what form and what controls are actually referencing.
(in fact the code will not compiled if those controls don't actually desist
on the form).
You code will thus look like:
Private Function GetMyValuesClause() As Collection
Set GetMyValuesClause = New Collection
GetMyValuesClause.Add cmbEmployeeName.Value
GetMyValuesClause.Add cldActivity.Value
GetMyValuesClause.Add cmbActivityCode.Value
GetMyValuesClause.Add textComments.Value
GetMyValuesClause.Add chkTransfer.Value
GetMyValuesClause.Add Item:=DLookup("[EmployeeID]", _
"SP_GET_CURRENT_EMPLOYEE_BY_WINDOWS_ID", _
"[Windows_AD_ID] = " & """" & fOSUserName() & """")
Call CleanMyCollection(GetMyValuesClause)
End Function