?
Solved

select query  access 2000

Posted on 2005-03-03
3
Medium Priority
?
253 Views
Last Modified: 2012-06-27
i am using the query listed below to access data from a table,the problem exists if there's no data,i would get an error messasge,I would if code1 doesn't return a value then the criteria should be code2 here are the codes.
thanks

code 1
sql = "select * from tblhourlymtr where hrzone=" & Me.Zone & " AND hrsection=" & Me.Section1 & ";"
Set rs = CurrentDb.OpenRecordset(sql)
Me.txtempname = rs.Fields("hrname")
code2
i would like it to use this code if no values are found on the first code
sql = "select * from tblhourlymtr where hrjob='" & Me.txtjob & "' AND hrsection=" & Me.Section1 & ";"
Set rs = CurrentDb.OpenRecordset(sql)
Me.txtempname = rs.Fields("hrname")
0
Comment
Question by:wwstudioinc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 2000 total points
ID: 13452605
You can check to see if no data is returned by using an If statement like:

sql = "select * from tblhourlymtr where hrzone=" & Me.Zone & " AND hrsection=" & Me.Section1 & ";"
Set rs = CurrentDb.OpenRecordset(sql)
If rs.EOF Then
   rs.Close
   sql = "select * from tblhourlymtr where hrjob='" & Me.txtjob & "' AND hrsection=" & Me.Section1 & ";"
   Set rs = CurrentDb.OpenRecordset(sql)
   Me.txtempname = rs.Fields("hrname")
Else
   Me.txtempname = rs.Fields("hrname")
End If
rs.Close
Set rs=Nothing
0
 
LVL 30

Expert Comment

by:hnasr
ID: 13452906
Comment from shanesuebsahakarn looks fine to me!
0
 

Author Comment

by:wwstudioinc
ID: 13452955
shane, you all guys are awesome,thanks alot for helping all the folks like myself.i love this web site
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question