An easy VB MS Access 2000 question

I have a single table (Employees) with 3 rows: Name, Age and Salary

I have one form with a command control

What code do I have to write in order to perform a simple search (salary>1000)
and print all the data relevant.
I've tried to write a code, but I'm having a problem with the CurrentDB.OpenRecordset and with the search function.

Please try to help me.
Thanks
alexelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

undagroundCommented:
Try this code

Dim salary(1 to 3) as integer, x as integer

Private Sub Command1_Click()
For x=1 to 3
If salary(x)>1000 then
Picture1.print salary(x)
End if
Next x
End Sub

Hope it helps!
-Mike
0
wide_awakeCommented:
dim rst as DAO.Recordset
set rst = CurrentDB.OpenRecorset "Select * from Employees where [Salary] > 1000"

do while !rst.EOF
  ' print the data from the current record
  Debug.print(rst("Name"))
  Debug.print(rst("Age"))
  Debug.print(rst("Salary"))
  rst.MoveNext
loop


That should do it...

-Mark
0
alexelAuthor Commented:
Mark

Thanks, but I'm getting a compile error on the:
Dim rst as DAO.Recordset

which is User Defined type not defined.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

arbertCommented:
Do you have a reference to the DAO object in your project????

Brett
0
wide_awakeCommented:
You have to add a reference for DAO - To do that in Access:

Go to the VB screen, then go to Tools -> References

In there, make sure "Microsoft DAO 3.6 Object Library" is selected.  Then it should recognize DAO.Recordset as a valid data type.


-Mark.
0
alexelAuthor Commented:
I've added the reference but now i'm getting a syntax error on the Select function
0
wide_awakeCommented:
If you just copy & pasted, I made a typo above... it should be

set rst = CurrentDB.OpenRecordset "Select * from Employees where [Salary] > 1000"

but I entered
> set rst = CurrentDB.OpenRecorset "Select * from Employees where [Salary] > 1000"

without a "d" in OpenRecordset

Ooops.

-Mark
0
alexelAuthor Commented:
I've noticed the typo and I've entered the code correctly, but I'm still getting a syntax error.

Do I have to perform additional references or to define something else?

Thanks
Alex
0
wide_awakeCommented:
What's the exact error you're getting?
0
alexelAuthor Commented:
After I'm clicking the command control, i'm getting a "compile error:syntax error" when the Select function is highlighted.
0
alexelAuthor Commented:
After I'm clicking the command control, i'm getting a "compile error:syntax error" when the Select function is highlighted.
0
wide_awakeCommented:
What's the exact error you're getting?
0
wide_awakeCommented:
Try this:

set rst = CurrentDB.OpenRecordset "Select * from [Employees]"


If that doesn't work, try doing this:

Dim strSQL as String
strSQL = "Select * from [Employees]"
set rst = CurrentDB.OpenRecordset strSQL

If that doesn't work, then something weird is going on.

-Mark.
0
alexelAuthor Commented:
Something weird is going on for sure.
The first option didn't work, as for the second it gave the syntax error on the:
set rst = CurrentDB.OpenRecordset strSQL

It seems like it doesn't recognize the CurrentDb parameter.

I'm increasing the points as this problem as not simple as I thought.
0
wide_awakeCommented:
if you type "CurrentDb." in the VB window, does it pop up a context menu with all the methods/attributes of CurrentDb?
0
wide_awakeCommented:
Oh - one other thing you might need to do is put the SQL string in parentheses.

set rst = CurrentDB.OpenRecordset(strSQL)

0
wide_awakeCommented:
Oh - one other thing you might need to do is put the SQL string in parentheses.

set rst = CurrentDB.OpenRecordset(strSQL)

0
wide_awakeCommented:
Heh, it's pretty easy to submit the same comment multiple times by accident eh?  :)
0
kiranghagCommented:
remove [] from the query
0
wide_awakeCommented:
any luck?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alexelAuthor Commented:
Hey Mark

Sorry for the delay.
Anyway, it still doesn't work, but I'll give you the points for youre help

Thanks
Alex
0
wide_awakeCommented:
If you type "CurrentDb." does it come up with a context menu?  

if not, it's probably a missing reference.

If you go to the VB Window, and go to Tools -> References, which libs have checks beside them?

-Mark.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Storage

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.