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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's Wrong with this Code - Getting error message

Status
Not open for further replies.

CDerosier

Programmer
Jan 5, 2003
10
0
0
US
I am trying to get my program to select records from a table using a field on a form as criteria, so that I can perform calculations on that data and return a value to another field on the form. I keep getting (Run-Time error 2465 Microsoft Access can't find the field '|' referred to in your expression)
the code is:

Dim sSQL As String
Set MyDb = CurrentDb
Dim TempGroup As String
location.SetFocus
TempGroup = Me.location.Text
sSQL = "Parameters TempGroup String; Select Location, MEASUREMENT from Table1 Where Location = tempgroup ORDER BY MEASUREMENT"
Set MyRS = MyDb.OpenRecordset([sSQL], [adReadOnly])

What am I doing Wrong?
 
I think you want
sSQL = "Parameters TempGroup String; Select Location, MEASUREMENT from Table1 Where Location = tempgroup ORDER BY MEASUREMENT"

to be
sSQL = "Parameters TempGroup String; Select Location, MEASUREMENT from Table1 Where Location = '" & TempGroup & "' ORDER BY MEASUREMENT"
 
I tried what you suggested, however I am still getting the same error message when I step through the code it stop on this line:

Set MyRS = MyDb.OpenRecordset([sSQL], [adReadOnly])

is there something I am leaving out?
 
It's something you're leaving in. If you remove the brackets from the arguments in the "Set MyRS = MyDb.OpenRecordset([sSQL], [adReadOnly])"
, I'm pretty sure you will lose that error. When you bracket an argument, Access will look for a field in your recordset, instead of the variable sSQL.

Example:
Set MyRS = MyDb.OpenRecordset(sSQL, adReadOnly)

Peace
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top