![]() |
|
|
#1
|
|||
|
|||
|
Hi,
I am trying to get my report to hide certain fields from the table. I was successful to do this with data in the first row of the table, but the code does not seem to repeat to row 2 of the table. I will post my code below, any help would be great. I know the table is not normalized, but for what we are working with that is the way it is. How do I get the code to loop through all the rows in the table and stop? Option Compare Database Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) End Sub Private Sub Report_Open(Cancel As Integer) Dim myrs As Recordset Dim myvar1, myvar2, myvar3 As String Dim conn As Connection Set conn = CurrentProject.Connection Set myrs = New Recordset myrs.Open "[Audit Issues 2009]", conn, adOpenDynamic, adLockOptimistic myrs.MoveFirst While Not myrs.EOF If IsNull(myrs("Follow-Up Testing Required (1)")) Then Me.Scope_of_Review__1_.Visible = False Me.Finding_Detail__1_.Visible = False Me.Management_Response__1_.Visible = False Me.Results_of_Follow_Up__1_.Visible = False End If If IsNull(myrs("Follow-Up Testing Required (2)")) Then Me.Scope_of_Review__2_.Visible = False Me.Finding_Detail__2_.Visible = False Me.Management_Response__2_.Visible = False Me.Results_of_Follow_Up__2_.Visible = False End If If IsNull(myrs("Follow-Up Testing Required (3)")) Then Me.Scope_of_Review__3_.Visible = False Me.Finding_Detail__3_.Visible = False Me.Management_Response__3_.Visible = False Me.Results_of_Follow_Up__3_.Visible = False Exit Sub End If Wend End Sub |
|
#2
|
||||
|
||||
|
You should not need a recordset or a loop. Test the fields and set the visibility in the detail format event. That will fire for every record. Don't forget to include an Else clause to set it the other way.
|
|
#3
|
|||
|
|||
|
Thanks for the reply.
However, I am very new to this and need help with the Else statement you talk about. |
|
#4
|
||||
|
||||
|
In pseudo code:
Code:
If Whatever Then set fields to not visible Else set fields to visible End If |
|
#5
|
|||
|
|||
|
Well I am still having some trouble. Only the 1st record (row) in my table works. When it goes to the 2nd record in the table the visible code does not work . Here is my code. Thanks so much for your help
Option Compare Database Private Sub Report_Open(Cancel As Integer) Dim myrs As Recordset Dim myvar1, myvar2, myvar3 As String Dim conn As Connection Set conn = CurrentProject.Connection Set myrs = New Recordset myrs.Open "[Audit Issues 2009]", conn, adOpenDynamic, adLockOptimistic If IsNull(myrs("Follow-Up Testing Required (1)")) Then Me.Scope_of_Review__1_.Visible = False Me.Finding_Detail__1_.Visible = False Me.Management_Response__1_.Visible = False Me.Results_of_Follow_Up__1_.Visible = False Else Me.Scope_of_Review__1_.Visible = True Me.Finding_Detail__1_.Visible = True Me.Management_Response__1_.Visible = True Me.Results_of_Follow_Up__1_.Visible = True End If If IsNull(myrs("Follow-Up Testing Required (2)")) Then Me.Scope_of_Review__2_.Visible = False Me.Finding_Detail__2_.Visible = False Me.Management_Response__2_.Visible = False Me.Results_of_Follow_Up__2_.Visible = False Else Me.Scope_of_Review__2_.Visible = True Me.Finding_Detail__2_.Visible = True Me.Management_Response__2_.Visible = True Me.Results_of_Follow_Up__2_.Visible = True End If End Sub |
|
#6
|
||||
|
||||
|
Like I said, there should be no need for a recordset, and the appropriate place for the code is the detail format event. That event fires for each record.
If IsNull(Me.Whatever) Then |
|
#7
|
|||
|
|||
|
I think I am slowly making progress here. I took out all references to the recordset, but now the code does not appear to be hiding anything like it should.
Maybe i just put it in the wrong place. I am not sure where the 'detail format event' place you mentioned above. But I went to 'design view' 'event' 'on open' and put [event procedure] and put code there. Here is my new code. Thanks for your patience. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) If IsNull("Follow-Up Testing Required (1)") Then Me.Scope_of_Review__1_.Visible = False Me.Finding_Detail__1_.Visible = False Me.Management_Response__1_.Visible = False Me.Results_of_Follow_Up__1_.Visible = False Else Me.Scope_of_Review__1_.Visible = True Me.Finding_Detail__1_.Visible = True Me.Management_Response__1_.Visible = True Me.Results_of_Follow_Up__1_.Visible = True End If If IsNull("Follow-Up Testing Required (2)") Then Me.Scope_of_Review__2_.Visible = False Me.Finding_Detail__2_.Visible = False Me.Management_Response__2_.Visible = False Me.Results_of_Follow_Up__2_.Visible = False Else Me.Scope_of_Review__2_.Visible = True Me.Finding_Detail__2_.Visible = True Me.Management_Response__2_.Visible = True Me.Results_of_Follow_Up__2_.Visible = True End If End Sub |
|
#8
|
||||
|
||||
|
A quick way to test if the code is running is to either set a breakpoint or throw a message box in there. One thing I notice is that you want brackets rather than quotes:
If IsNull([Follow-Up Testing Required (1)]) Then Brackets would designate a field, the quotes would be treated as a literal string, which would never be Null. |
|
#9
|
|||
|
|||
|
Great. The brackets were the trick. I am past that road block now. Thanks for all your help.
|
|
#10
|
||||
|
||||
|
No problem. I should mention that the brackets are only required because of the spaces and symbols in your names. In the long run, you'll find those aren't worth the bother. I'd get rid of them if it's not too late.
Welcome to the site by the way! |
|
| Bookmarks |
| Tags |
| loop table, records, vba |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| VBA code - questions table onto forms | Tman | Programming | 3 | 04-26-2010 03:47 AM |
| Expand entire row not just single cell in a Report | CityOfKalamazoo | Reports | 1 | 03-05-2010 06:33 AM |
| Closing form minimizes entire Ms Access Application | jermaine123 | Forms | 9 | 12-28-2009 01:01 PM |
| update table in loop based on IF statement | LALouw | Access | 0 | 07-26-2009 06:46 PM |
| Loop a table to use field in query | jdubp | Programming | 0 | 03-04-2008 08:48 AM |