473,386 Members | 1,860 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,386 software developers and data experts.

Identifying fields in a recordset where a wild card is used in SQL statement

I have a piece of code I use to compare two identically structured
tables. There are 15+ sets of tables I am comparing. I am looking to
see what has changed between the "old" and "new" versions of the table.
Any changes get reported to an audit file which contains the index,
field name and field value of the records that have changed. I have
the changes nailed for modifications, but cannot seem to get a handle
on adds/deletes.

Due to the somewhat dynamic nature of the tables I am comparing, I
wanted to avoid having to create separate queries for each set of
tables. Here is the statement I am using to do the "Find Unmatched":

Set tmpb = db.OpenRecordset("Select * from " & btbl & " left join " &
ctbl & " on " & btbl & "." & cfield & " = " & ctbl & "." & cfield & "
Where " & ctbl & "." & cfield & " is null;")

btbl = baseline table, ctbl = current table, cfield = common field
between the tables

This runs just fine.

Now I want to see the actual fields that are part of this recordset.
From there, I will go field by field and append the field name and

field value into an audit table.

I have a hunch I should do something involving TableDef with this, but
cannot seem to figure it out.

Any ideas?

Nov 13 '05 #1
2 1982
This might be long, but I'll try to keep it as simple as possible...

You're using DAO... good, Makes life easier for me!

What you need to do is just walk down the hierarchy a little further.

database ==> tabledefs collection ===> fields collection of tabledef.

ONE way of doing this is to break out the "get the delimited field list
from the table" as a separate function - it makes it possibly reuseable
and MUCH easier to debug, should you make a mistake somewhere.

Here's part of the code... tweak as necessary...
'--BEGIN CODE

Option Compare Database
Option Explicit

Public Function GetFieldList(ByVal strTable As String, Optional ByVal
strSep As String, Optional ByVal blnIncludeTableNames As Boolean) As
String

'INPUTS:
'1. strTable - the name of the table you want the fields from
'2. strSep - the delimiter you want between your fields, like
comma-space, or semicolon (good if you want to create a rowsource for a
listbox)
'3. blnIncludeTableNames - if you need the tablenames included, i.e.
"TableA.FieldA1" instead of just FieldA1, set this to True)

Dim db As DAO.database
Dim tdf As DAO.tabledef
Dim intCounter As Integer

If IsMissing(strSep) Then
strSep = ", "
End If

If IsMissing(blnIncludeTableNames) Then
blnIncludeTableNames = False
End If

Set db = CurrentDb
Set tdf = db.tabledefs(strTable)

For intCounter = 0 To tdf.Fields.Count - 1
If Len(GetFieldList) = 0 Then
If blnIncludeTableNames Then
GetFieldList = "[" & tdf.Name & "].[" &
tdf.Fields(intCounter).Name & "]"
End If
Else
GetFieldList = GetFieldList & strSep & "[" & tdf.Name &
"].[" & tdf.Fields(intCounter).Name & "]"
End If
Next intCounter

Set tdf = Nothing
Set db = Nothing
End Function

'---END CODE

Okay, so then you have to create your query SQL in another function.

Function QuerySQL(byval strTableA as string, byval strTableB as string,
byval strDelimiter, blnIncludeTableNames as boolean) As string
' --- call the above function for both tables to get the list of
fields.
' --- prepend the "SELECT "
' --- create and add the "FROM tableA LEFT JOIN tableB ON A.PK=B.FK...
statement
' --- add the WHERE statement, if necessary.
End Function

Isn't this fun? Man, after this, I *really* think the QBE grid is
cool!!! <g>

Hope this gets you started!

Pieter

Nov 13 '05 #2
sorry, me again. You might want to look at this article and see if
this might help you in the future...

http://members.iinet.net.au/~allenbrowne/AppAudit.html
It does all the logging for you.

Nov 13 '05 #3

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

Similar topics

4
by: kiqyou_vf | last post by:
i know i know, wysiwyg's are not for loosers and all that but i've been coding php for about 6 months now and the one thing ive always wanted to do was see a live preview of my php so i can format...
1
by: monika | last post by:
I move from one form to another when I click to a radio button. I can identify which radio button I clicked by trapping its value. but my problem is that there are a set of radio buttons followed...
4
by: Tom | last post by:
I want to open a recordset object on an .asp page. When I open the recordset I would like to use a stored procedure that expects a parameter to be passed for the stored procedure. I will then use...
12
by: Patrick | last post by:
I have two ASP pages payment.asp: For customers to fill in payment/card details (pre-populating details if details submitted were invalid and user had to re-fill in details) confirmorder.asp:...
1
by: Tempy | last post by:
Could somebody please tell me if it is possible and if how? I am wanting to do : Iif(="*PE","Y","N") In other word i want it to fine HZPE, AEPE, HEPE etc... Les Stout *** Sent via Devdex...
3
by: alex_peri | last post by:
Hello All, I am having problems with sorting a recordset by fields in Access. I have a table with three columns called ID, SNo and Time and would like to sort the records by Time. I would like to...
2
by: psbasha | last post by:
Hi, How to get a File Wild Card using Tkinter Module?. Could anybody has used this option.If so, the smaple snippet of the code will really help me. Thanks PSB
0
by: shamaila | last post by:
wild card characters are used to match strings as select * from table where name LIKE '%brown%'; but doesnt supports matching of dates,number what will we do if we want approximate matching of...
7
by: W. eWatson | last post by:
Is it possible to do a search for a wild card string in another string. For example, I'd like to find "v*.dat" in a string called bingo. v must be matched against only the first character in bingo,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.