Hi Ban
I think I am close. Please tell me if what I say below is wrong; Please put
up with if it looks childish;
When you write an SQL procedure in Access you cannot do a sub procedure
within the main procedure like we do in VBA. Example;
Sub MainProcedure ()
Workbooks.Open "kfgr.xls" 'Procedure 1
Cells(1,1).Select 'Procedure 1
Call hhvsajc 'Procedure 2
End Sub
That is correct; you cannot. What you have above is good (Excel dialect of)
VBA, and with the appropriate library references could be called from an
Access VBA Module, but it is not valid SQL (not in Access/JET SQL or to my
knowledge any other flavor of SQL).
And
We cannot delare variables within the SQL statements we build in Access.
Example;
SELECT BCST.TransactionNumber
FROM BCST
WHERE (((BCST.TransactionNumber)=14283));
If I want 14284 I should do a seperate query whereas in a stored procedure I
can do 'Dim TransactionNumber as Integer' and change the number without doing
an other query.
This is valid SQL. You cannot Dim a variable - but you can come awfully close,
using a Parameter instead.
SELECT BCST.TransactionNumber
FROM BCST
WHERE (((BCST.TransactionNumber) = [Enter Transaction Number:]));
will pop up a prompt on the screen saying "Enter Transaction Number:" and the
search will return that result.
It's optional (but usually prudent) to declare the parameter in the Query:
PARAMETERS [Enter Transaction Number:] Integer;
SELECT BCST.TransactionNumber
FROM BCST
WHERE (((BCST.TransactionNumber) = [Enter Transaction Number:]));
In practice, it's very common and desirable to use a reference to a Form
object as a parameter. The query will pull the value from that form object (if
the form is open!!) rather than popping up a prompt. E.g.
=[Forms]![frmCriteria]![txtTransNo]
will use whatever value exists in the textbox named txtTransNo on frmCriteria
as a criterion.