473,408 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

dlookup or find methods for fileds using balue for field name

3
i read the thread entitled "Convert Field Value String to Actual Field in Expression"

It appeared that the final solutions got moore complex not less complex

MY PROBLEM IS:
1. get a value from one table as a string
2. lookup the value of a field in a second table
where the field name = the value of field in table 1

I CAN GET THIS USING DLOOkUP, BUT NOT BY FIND METHOD
example:
c = value from tableR2 (if [PART] - "AN" then c = "HD1")





HERE IS MY CODE
Dim CX As Variant 'Specific HX DATE
Dim C As Variant
DIM SQL as String



Dim R1 as Recordset
' HX_DATES (PATID as Long), HD1, HD2 HD3 HD4 as Dates (double)
Dim R2 as Recordset
'HX_LIST ( PART as string) LIST OF HX VALUES
C = Null
CX = Null
SQL = "Select * from HX_LIST where [PART] = 'AN' ;"



Set R1 = DB.OPENRECORDSET("HX_DATES", Db_readonly)
SET R2 = DB.OPENRECORDSET (SQL)

PROBLEM:
Moving to first record of R2 gets value of "H01" (this is a string)
As example R2!H01 = #2/3/2006#
=========
THIS WORKS: CX = DLookup("" & C & "", "tmp_hex", "patid = " & PATID)

WHAT I WANT IS
R1.findfirst "PATID = " & PATID (This works)
C = "R!" & C (Makes C = R1!H01)
CX = R1!H01 (I want CX = #2/3/2006#)
Oct 22 '06 #1
1 1481
MMcCarthy
14,534 Expert Mod 8TB
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim CX As Variant 'Specific HX DATE
  3. Dim C As Variant
  4. Dim SQL As String
  5. Dim db As DAO.Database
  6. Dim R1 As DAO.Recordset ' HX_DATES (PATID as Long), HD1, HD2 HD3 HD4 as Dates (double)
  7. Dim R2 As DAO.Recordset 'HX_LIST ( PART as string) LIST OF HX VALUES
  8.     C = Null
  9.     CX = Null
  10.     SQL = "Select * from HX_LIST where [PART] = 'AN' ;"
  11.     Set db = CurrentDb
  12.     Set R1 = db.OpenRecordset("HX_DATES", DB_READONLY)
  13.     Set R2 = db.OpenRecordset(SQL)
  14.     rs2.MoveFirst
  15.     C = rs2!HO1
  16.  
  17.     With R1
  18.         .FindFirst "PATID = " & PATID
  19.         CX = .Fields(C)
  20.     End With
  21.  
  22.     R1.Close
  23.     R2.Close
  24.     Set R1 = Nothing
  25.     Set R2 = Nothing
  26.     Set db = Nothing
  27.  
  28.  
Oct 22 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: JLM | last post by:
What am I missing here? I have a form where I enter a "Class Code". This value corresponds to what sits in table "class code descriptions" along with the "title" of each "class code." Key...
6
by: LSemos | last post by:
I am trying to lookup phone numbers in a separate table based on the name in the current Tab control tblContacts has the fields: Name, Phone, Fax, and Email In my Form's Tab control, I have...
1
by: mstery | last post by:
I have a report generated via an ID selection made in a dropdown on a form. The report filters by an on click event in a preview report button on the form. Everything in the report, including...
4
by: basstwo | last post by:
I have a field with a serial number in it. I want to use Mid to extract the 4th and 5th characters, use them to lookup a value on a small lookup table, and use the info from that table to fill in...
8
by: Christine Henderson | last post by:
I have a problem using the above function in the following simplified circumstance: In the lookup table called "Klms Travelled" I have 3 fields, eg: Receiver Name Receiver Suburb ...
6
by: Don Sealer | last post by:
I've written this expression for a DLookup function. It works almost alright. What I'm trying to do is type in a description and the ID field (number) populates automatically. It works almost as...
1
by: BobM | last post by:
i read the thread entitled "Convert Field Value String to Actual Field in Expression" It appeared that the final solutions got moore complex not less complex MY PROBLEM IS: 1. get a value from...
1
by: BobM | last post by:
i read the thread entitled "Convert Field Value String to Actual Field in Expression" It appeared that the final solutions got moore complex not less complex MY PROBLEM IS: 1. get a value from...
1
by: Deac | last post by:
I was asked to help a friend with a database and am in over my head! The customer table has been in place and they have used a paper copy of the pricing table to make manual changes and...
6
by: David Wright | last post by:
Hello Folks I am using Microsoft Access 2000 I would be grateful if someone could help me with “Dlookup”. I tried various methods of writing Dlookup and various events to trigger it, none of...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.