> Hello Ida,
>
[quoted text clipped - 12 lines]
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/Forums.aspx/access-queries/200511/1
Well I could either delete them or not show them. Either way, if I were
to use SQL programming, I am unfamilar as to how to do loops and pass
variables in SQL.
For example, the example I gave you was just one case. But the code
needs to be able handle any future case. So in other words, I might
have 10 fields, or I might have 50 fields. I won't be able to manually
select each column if i I have 50 fields. I need the code to do it.
Plus, I just don't want to hide or delete all columns that have no
values. I want to hide or delete only the columns that have no values
AND neither do all of the columns after them.
David S - 18 Nov 2005 02:04 GMT
>Well I could either delete them or not show them. Either way, if I were
>to use SQL programming, I am unfamilar as to how to do loops and pass
>variables in SQL.
Me too. I guess this explains why I wasn't understanding it - so you want to
output a line of data using code, rather than using a query to display the
results?
In theory, you should be able to loop around the fields in each record
returned with something like:
Dim oRS As Recordset
Dim iFld As Integer
Dim iCount As Integer
Dim oFld As Field
Set oRS = CurrentDb.OpenRecordset(sTableName, dbOpenTable)
iFld = 0
iCount = 0
For Each oFld In oRS.Fields
iCount = iCount + 1
If oFld.Value Is Not Null Then iFld = iFld + 1
Next oFld
That would give you the count of the last field with data in it, and then you
should be able to loop around the field until you get to that field. Unllike
that first bit, I don't have the code in a nearby database for me to post for
you - maybe someone else can continue with the next bit? Pseudocode-wise,
it'd look like:
For i = 1 to iCount
If i = 1 Then
sOutput = oRS.Fields(0)
Else
sOutput = sOutput & "," & oRS.Fields(i-1)
End If
Next i
write sOutput
or something like that...