Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

select query  access 2000

Posted on 2005-03-03
3
Medium Priority
?
257 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
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 31

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
A Case Study of using the Windows API to provide RS232 communications capability in Access without the use of Active-X controls.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

564 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