Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global Variable problem

Status
Not open for further replies.

FranS37

Programmer
Jun 6, 2002
59
US
I set a global variable in the declarations section of a form - Public PONumber as Long

Then in the click event of a command button on the form I use:

POnumber = Me![PurchaseOrderNo]
Set dbs = CurrentDb
stSql = "SELECT * FROM [InventoryTransactions]"
stSql = stSql & " WHERE [PurchaseOrderNo] = PONumber"
stSql = stSql & " ORDER BY gponumber;"
Debug.Print stSql
Set rs = dbs.OpenRecordset(stSql, dbOpenDynaset, dbSeeChanges)

The debug.print shows that the variable in the SQL is not finding the number even though
POnumber = Me![PurchaseOrderNo] is finding it

I get an error 'Too few parameters. Expected 1' when the on the set rs = ...

I guess there's something wrong with my SQL.
Can anyone help?

Thanks.

Fran

 
Fran,

It looks to me that you have split up your code. A Simple way to see if you have written your code properly is to write a query and look at it in SQL view.

Try this code:

Code:
POnumber = Me![PurchaseOrderNo]
Set dbs = CurrentDb
stSql = "SELECT * FROM [InventoryTransactions]WHERE ((( nameoftable.[PurchaseOrderNo]) = Forms!Formname!PONumber))ORDER BY Nameoftable.gponumber;"
Debug.Print stSql
Docmd.RunSQL stsql
Set rs = dbs.OpenRecordset(stSql, dbOpenDynaset, dbSeeChanges)

I can't make any garuntees that this code will work, but you can see how the SQL is all in one now?

Hope this helps

Cheers

Dean
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top