LilMorePlease said:
Hi Dirk,
Thank you for your helpful suggestions.
You're welcome.
I cleaned up several things
that you pointed out. I have a question about one thing you said:
Select Case Me!optTranType
The TypeNum field is actually a number field. How do I code this so
there is not a conversion? I've tried a few things, but haven't
figured it out.
The literals are easy. The combo box's column is always going to have
to be converted, so you probably don't have to concern yourself with it;
you could change the code to read as follows:
Select Case Me!optTranType
Case 1: !TypeNum = 19
Case 2: !TypeNum = 20
Case 3: !TypeNum = Me!cboNonOverride.Column(2)
End Select
If you want, you can force an immediate conversion to the data type of
TypeNum. For example, if TypeNum is a Long Integer, you could write
this:
Select Case Me!optTranType
Case 1: !TypeNum = 19&
Case 2: !TypeNum = 20&
Case 3: !TypeNum = CLng(Me!cboNonOverride.Column(2))
End Select
Now, *that's* getting really finicky. The '&' suffix on the numeric
literals specifies that these literals represent Long Integer values,
not just Integers. I wouldn't normally bother with that, except maybe
in code that will run many times in a tight loop, where the utmost
efficiency is required. The use of the CLng() function ensures that the
combo column is converted directly to a Long Integer value, just in case
the compiler might take it into its head to use some intermediate type.
I don't know that the compiler would do that, so as I said, this is very
finicky indeed.
For most purposes, I'd just use the first of the two versions I posted
above. After all, what you gain in execution efficiency now, you might
lose later if you changed the data type of TypeNum from Long Integer to
Integer, or some other numeric type.
I have another problem I was hoping you could help me with as well.
Now that I can successfully add records to the AssignedBatches table,
the next step is to show the user the added records. What I am
trying to do is query the function that contains the current batch
numbers. The batch numbers are stored in a Public Function called
GetBatchNumbers() within the current form. I created a query
detailing all the fields the user needs to see with the criteria:
Where MasterBatch.BatchNum = GetBatchNumbers()
That's not going to work, even if you add the required reference to the
form itself, to qualify the function call:
WHERE MasterBatch.BatchNum =
Forms!YourForm.GetBatchNumbers()
The above is the way you have to refer to a public function defined in a
form, from anyplace not on that form itself (as your query is not).
HOWEVER, the above still won't work! And it wouldn't work even if you
moved the function to a standard module and dropped the "Forms!FormName"
qualifier.
I'm not sure what you mean when you say the batch numbers are "stored in
a Public Function", but the function can only return one thing. That
thing may be a string containing a list of batch numbers, or it may be
an array of them, or it may be a collection of them, but as far as the
SQL expression is concerened, your WHERE clause is comparing one
"thing" -- MasterBatch.BatchNum -- to another "thing" -- the return
value of GetBatchNumbers(). The two things have to be comparable, and
if one is a single number and the other is a string, array, or
collection of numbers, they just aren't comparable.
What you want, as I understand it, is to set up a WHERE criterion that
evaluates to True of MasterBatch.BatchNum is *in* the
list/array/collection. There are several ways you could go about doing
that, including using an alternate version of the function that receives
a batch number as an argument and returns True or False depending on
whether the batch number is in the list. However, that may not be the
most efficient way of doing it. It will depend on what you mean when
you say, "The batch numbers are stored in a Public Function". If you'd
like to post the code for the function GetBatchNumbers(), I'll try to
make a better suggestion.