Parameter Query - Chris ?!?!

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hope Chris is here - helped before.
You wrote piece of code for me, worked - but when I transfer it to my
database, the line that goes strTrack = "Track" does not make sense to me.
The word Track does not appear without a 1,2 after it, yet your code finds
both tracks, one in each "track"column, in other words it searches "Track1" &
"Track2" column - how ?? My track clumns are called "a1", "a2" etc. but
unless it change "strTrack = "a1" etc. it does not work at all - yours
searches all the columns, mine only the one named e.g. a1 - I have checked
over the module - all looks okay otherwise ?!
Al
 
al9315 said:
Hope Chris is here - helped before.
You wrote piece of code for me, worked - but when I transfer it to my
database, the line that goes strTrack = "Track" does not make sense to me.
The word Track does not appear without a 1,2 after it, yet your code finds
both tracks, one in each "track"column, in other words it searches "Track1" &
"Track2" column - how ?? My track clumns are called "a1", "a2" etc. but
unless it change "strTrack = "a1" etc. it does not work at all - yours
searches all the columns, mine only the one named e.g. a1 - I have checked
over the module - all looks okay otherwise ?!
Al

Al,

Hi!

I remember what you're talking about.

It's possible to refer directly to a column name by it's title.

If you check the line of code again, it actually is a bit longer than
you show above.

I reproduce the relavant section here:

<code snip>
Dim strTrack As String

strTrack = "Track"

rs.MoveFirst

With rs
Do Until .EOF
For Each fld In .Fields
If Left(fld.Name, 5) = strTrack Then
If fld.Value Like "*" & SearchParameter & "*" Then
lngRowFound = .Fields("AlbumID").Value
' The following will print results in the
'immediate window in the Visual Basic Editor.
' It needs to be replaced with whatever you
'want to do with the output data.
Debug.Print lngRowFound
End If
End If
Next
.MoveNext
Loop
End With

<code snip>


If you see, it says:

If Left(fld.Name, 5) = strTrack Then

If you'll remember, my example database had Track1 and Track2 as the
column names. The leftmost 5 characters = "Track". The other columns
don't start with Track. That makes this code skip over any column
name not starting with "Track". strTrack should really be a const,
but I was lazy. You can really call it strFieldNameHeader, and make
it equal to "a". I hope all the relavant columns in the Table are the
only ones starting with "a", though, because this code will execute on
*any* column starting with the letter "a" (or whatever value is put in
the variable).

By the way, you really should be looking at normalizing your Tables.
Using the above code is a *major* kludge, a work-around that's really
ugly.


Sincerely,

Chris O.
 
Back
Top