Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking whether a field exists in report's recordset

Status
Not open for further replies.

Katerine

Programmer
Mar 9, 2001
234
US
Hi,
I have a rather unusual request; I need to check (in an A2K database) whether a given field exists in the report's recordset. I've noticed that this is actually really easy to do with forms:

dim rs as dao.recordset,fld as field
set rs=me.recordsetclone
for each fld in rs.fields
if fld.name=strFieldName then <field exists>
next fld

..but I need to do this with a report, and there doesn't seem to be anything comparable.

Help? Katie
 
You should be able to use the RecordSource property to get the data source for the report. You can open a new Recordset based on the report source, then use the method that you used on the form. I've written the example below using an ADO Recordset, but you should get the idea.



Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Dim source As String

source = Me.RecordSource
Set rst = New ADODB.Recordset
rst.Open source, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly

For Each fld In rst.Fields
If fld.Name = strFieldName Then
Debug.Print &quot;HELLO&quot;
End If
Next fld

rst.Close
Set rst = Nothing

 
Tried that :) Unfortunately, we're asked for parameter values, and we need to run so many reports, it's not enough to go through filling in parameter values.

However, since I posted this morning, my coworker found a workaround, using a combo box set to field list, and checking for the field in the combo's itemdata.

Thanks anyway! Katie
 
Someone before was trying to print the recordsource to all their forms. We determined that the recordsource can't be viewed without opening the form. Getting recordsource of reports works the same way.

For i = 0 To CurrentProject.AllReports.Count - 1
DoCmd.OpenReport CurrentProject.AllReports(i).Name, acViewPreview
str = str & Reports(0).Name & &quot;: &quot; & Reports(0).RecordSource & Chr(13)
DoCmd.Close acReport, Reports(0).Name
Next i

I'm curious how you're doing it with a combobox.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top