Determine the currently selected field & row

T

Terry Hornsby

I have a colleague at work who wants to determine the field name from the
currently selected record in a query table & dynamically use this field name
in the select query statement of the same query table.

He was wanting to use a function which would convert the records in the
field (presumably the currently selected record) from a text value into a
date value & perform a datediff on it.

I argued that he couldn't do this because he would be altering the
underlying structure of the current query which would alter the cursor
position in the table which in turn would alter the query statement & so
on - into a loop.

The reason he wants to do this is because he has to create & run an
indefinite but large number of access query tables & perform the same
datediff calculation, but he doesn't know in advance what fields will
contain the dates he needs to work with & how many fields there will be.

This is because the raw data is imported from text files supplied by the
local council's IT department (created from running a routine on proprietary
software with a limited query language), where the dates could appear at any
position in the text string.

I had suggested to him that he prefix all the date fields with a key
identifier & number them consecutively & he could then loop through the
fields in code. But this would require an amount of manual work on each
database he creates, which he is not prepared to do (he needs REALLY fast &
dirty solutions).

Converting the text into a date & performing a datediff in a function is no
problem, but although you can determine the current record number in the
function, you can't determine the field. This has to be done in his query
statement, which means a manual editing job & we're back to the problem of
it not being quick enough.

So, my questions are:

1) Can a function be written which returns the correct record from the
correct field, namely the currently selected one?

Specific to this newsgroup: -
2) Is it impossible to change the underlying query statement of the
currently active query table when the change itself relies on a change
(i.e., detection of the currently selected field)

3) Could the way forward be to wrap the way the text file is imported within
a function of some kind which automatically reformats date strings to date
values as it populates the table & if so, can it be dynamic because the
position of the date field data would not be known in advance?

I was thinking of some kind of dynamic import data / createtable routine.
Can anyone give an example?

I've not cross-posted this, but understand that only one of the possible
solutions is relevant to this newsgroup. However, any solution would be
greatly appreciated.

Terry Hornsby
 
M

[MVP] S.Clark

I don't understand the goal, and there is a lot of info here to digest. So,
I'm going to start at the first confusing thing, and ping back for
clarification.

Confusing Item #1: "to determine the field name from the currently selected
record in a query table"

Does this mean that the 'query table' is only returning one field per
record?
Is a 'query table' the query result or the underlying table for the query?
What is the SQL for the query, and what are some example records from the
data import?


--
HTH,

Steve Clark, Access MVP
FMS, Inc.
Professional Solutions Group
http://www.FMSInc.com
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Is your Access database too slow?
Are you ready to upgrade to SQL Server?
Contact us for optimization and/or upsizing!
http://www.FMSInc.com/consulting
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
T

Terry Hornsby

My colleague has a number of existing tables & will probably be creating
more derived from converting text files (data extracts) he is given & has no
control over.

He uses a fairly standard query table as a template to convert the date
strings in the base tables to date values so he can then perform a datediff
on them.

But he has to manually amend the bits of the sql which refer to the fields
containing the date strings because he doesn't know, in advance, what column
they will appear in or how many columns there will be.

I guess that what he was wanting to do was programmatically identify which
fields contained the date strings so that the query table would
automatically change the strings to date values on open. He could then
choose a date record from the opened query table just be clicking on it &
have that action perform the datediff he was wanting. For some reason he
needs to know the field name of the field containing the selected record, so
the action of selecting the record would need to return the field name.

He didn't make clear whether or not he wanted the underlying field name of
the base table or the currently selected field name in the query table, but
if one is provided I could possibly work out how to derive the other from
this.

To answer the two queries you have:
1) The query tables will produce hundreds to thousands of records
2) The underlying sql for the query table is what he wishes to manipulate.
He was talking about changing this AFTER it had opened, but this would
appear to be an impossibility! So I've tried to interpret his wishes the
best way I can & hope the explanation above is clearer.

No worries if this is still clear as mud as I don't have access to his
work...this is the council for you. One of us has the sql info & knowledge,
the other the programming know-how, but never the twain shall meet.

Best wishes,


Terry.

He was hoping to open the query
 
M

[MVP] S.Clark

Unfortunately, you did not answer my questions directly. Let's try again,
this time, don't provide any extra info. Overanalysis is adding confusion.

1. How many fields(Columns) are being returned PER record? (Answer should be
either 1 or Many).
2. When you say 'query table' is that the the query RESULT or the underlying
TABLE for the query?
(Answer should be either RESULT or TABLE)
3. What is the SQL for the query.
(Something like: Select * from tblStuff where StuffID = 1234)
4. What do a couple rows of the imported data look like?

Short, concise answers please.
 
T

Terry Hornsby

1) 1
2) table
3) they're all different. That's the point.
4) The data is all imported as text. These are fictional examples of what
the data would look like: -

QUERY 1:
Fld1 Fld2 Fld3
Fld4 Fld5
038465873 Y IS
04052003 05092003
20081973 Y JSA
04102002 05112003
048465892 N N
16051998 31012000

QUERY 2:
Fld1 Fld2 Fld3
Fld4 Fld5
20105873 Y 04052003 IS
05092003
02021973 Y 04102002 JSA
05112003
01065892 N 16051998 N
31012000

QUERY 3:
Fld1 Fld2 Fld3
Fld4 Fld5 Fld6
20105873 Y 04052003 NXPTQ
05092003 04052003
3010467873 Y 04102002 KJGUL
05112003 010101998
05112003 N 16051998
MYYHGT 31012000 28121992

QUERY1 date fields are Flds 4 & 5, QUERY2 they're Fld 3 & 5 & QUERY3 they're
3, 5 & 6
Fld1 in these cases are all unique claim numbers. No other details are
unique.

The solution therefore has to be very generic.

Steve, don't worry if you can't help. I know this is all a bit woolly,

Best,

Terry.
 
M

[MVP] S.Clark

Ok, your answer to question one is 1, meaning one field is returned from the
query, but in your query examples below, you show that there are 5 fields.
:shrug: I'm afraid I can't help, because I can't get straight answers. I'm
sure whatever your collegue wants to accomplish is possible, but I don't
forsee it happening through this medium.

Sorry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top