472,362 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,362 software developers and data experts.

Go to a Single Record. Dlookup or SQL Recordset?

When I use Dlookup. I am only able to return a single value and
therefore cannot seem to assign a single records (3-field values) to
(3-Variables). I noticed that I can get the 3-field values, but it is
returned as a single string, probably requiring parsing. Not Desirable!
Maybe I need Dlookup to get a unique key value, and then look again
for the record somehow? But, I understand that Dlookup has issues (ie
performance and reliability).

I am looking for a fast / reliable way of looking up a single record in
code, without affect my currently displayed record, and then fill my
variables. I read that a SQL /RecordSet marriage
of some sort is the way to go, but am lost on concept and syntax. Any
suggestions???

Greg

Jan 26 '07 #1
6 10088
dim rs as recordset
set rs = currentdb.opensrecordset("SELECT * FROM yourtablename WHERE
yourcriteria here")
something1 = rs!oneofyourfields
something2 = rs!anotheroneofyourfields
' do stuff
' close the recordset
rs.close
set rs = nothing

Cheers,
Jason Lepack

On Jan 26, 1:02 pm, "ApexD...@gmail.com" <ApexD...@gmail.comwrote:
When I use Dlookup. I am only able to return a single value and
therefore cannot seem to assign a single records (3-field values) to
(3-Variables). I noticed that I can get the 3-field values, but it is
returned as a single string, probably requiring parsing. Not Desirable!
Maybe I need Dlookup to get a unique key value, and then look again
for the record somehow? But, I understand that Dlookup has issues (ie
performance and reliability).

I am looking for a fast / reliable way of looking up a single record in
code, without affect my currently displayed record, and then fill my
variables. I read that a SQL /RecordSet marriage
of some sort is the way to go, but am lost on concept and syntax. Any
suggestions???

Greg
Jan 26 '07 #2
Thanks Jason

I tried the following code, but am getting a error "Missing operator in
query expression" on the Set rs line of my code, but can't figure it
out. Possible delimiter issue???

Dim rs As Recordset
Dim strSQL As String
strSQL = "SELECT * FROM [TL-ZIPCODE] WHERE ZIP = " & txtZIP
Set rs = CurrentDb.OpenRecordset(strSQL)
MsgBox rs!CITY
MsgBox rs!LNAME
' do stuff
' close the recordset
rs.Close
Set rs = Nothing

Any ideas???

Jan 26 '07 #3
i think you might have to put some more " " " around your txtzip and a me

strSQL = "SELECT * FROM [TL-ZIPCODE] WHERE ZIP = " & me.txtZIP & ""
OR
strSQL = "SELECT * FROM [TL-ZIPCODE] WHERE ZIP = """ & me.txtZIP & """"

i'm still half asleep, but hope this helps you

Ap******@gmail.com wrote:
>Thanks Jason

I tried the following code, but am getting a error "Missing operator in
query expression" on the Set rs line of my code, but can't figure it
out. Possible delimiter issue???

Dim rs As Recordset
Dim strSQL As String
strSQL = "SELECT * FROM [TL-ZIPCODE] WHERE ZIP = " & txtZIP
Set rs = CurrentDb.OpenRecordset(strSQL)
MsgBox rs!CITY
MsgBox rs!LNAME
' do stuff
' close the recordset
rs.Close
Set rs = Nothing

Any ideas???
--
Regan,
Paeroa
World famous in New Zealand

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200701/1

Jan 26 '07 #4
I suspect that the field ZIP is a text field. Therefore you will need
to add "'" (which is " ' " without the spaces) before and after the
txtZip.

The new line will be:
strSQL = "SELECT * FROM [TL-ZIPCODE] WHERE ZIP = "'" & txtZIP & "'"

Cheers,
Jason Lepack

On Jan 26, 3:02 pm, "ApexD...@gmail.com" <ApexD...@gmail.comwrote:
Thanks Jason

I tried the following code, but am getting a error "Missing operator in
query expression" on the Set rs line of my code, but can't figure it
out. Possible delimiter issue???

Dim rs As Recordset
Dim strSQL As String
strSQL = "SELECT * FROM [TL-ZIPCODE] WHERE ZIP = " & txtZIP
Set rs = CurrentDb.OpenRecordset(strSQL)
MsgBox rs!CITY
MsgBox rs!LNAME
' do stuff
' close the recordset
rs.Close
Set rs = Nothing

Any ideas???
Jan 26 '07 #5

Thanks Regan

strSQL = "SELECT * FROM [TL-ZIPCODE] WHERE ZIP = """ & Left(txtZIP, 5)
& """"

This solved it. I need to study Quote Placement more!
I also needed to refine txtZIP to the five initial chars.

ThankYouALL
Greg

Jan 26 '07 #6
Thanks Jason

Greg

Jan 27 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ken Fine | last post by:
Suppose I've built a recordset. I want some code to run for each record in the recordset in a "loop." In ASP VBScript, how would you express the following: For each in next The only...
1
by: Stewart Graefner | last post by:
I have been unable to locate anywhere the answer to my problem. I would like to be able to download/import a single record. This record is stored in many different related (one to one) tables. I...
2
by: Harold | last post by:
Sat I have a customers table with the fields CustomerID and Customer and I use the recordset.addnew method to add a new record to the table. What is the best way to get the CustomerID of the new...
3
by: Peter Morris [Droopy Eyes Software] | last post by:
Hi all When I bind to multiple records I use a DataList. This allows the web-designer to add code like <%#DataBinder.Eval(Container.DataItem, "Name")%> Whenever I want to retrieve a single...
0
by: Andy | last post by:
Hi All. I'm working for a company that has set out a guideline for retrieving data from a database. Nobody can explain to me the reason for the following. When retrieving a set of records...
6
by: zoro | last post by:
Hi, I am looking for the recommended way to retrieve several values from a single record, i.e. a typical lookup scenario. An example would be a query that needs to retrieve user_name, user_addres,...
22
by: RayPower | last post by:
I'm having problem with using DAO recordset to append record into a table and subsequent code to update other tables in a transaction. The MDB is Access 2000 with the latest service pack of JET 4....
6
by: Aussie Rules | last post by:
Hi, In all my coding to date, i have been dealing with multiple results in my dataset, looping through them with SqlDataAdapterContactProfile.Fill(contact, "Profile") For Each pRow In...
2
by: jamieda | last post by:
I have a multiple items form displaying the contents of a table. It has a primary key and the records are ordered by this. I want to be able to manually select a record in the form and then...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
0
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.