Microsoft Access Forums

Go Back   Microsoft Access Forums > Access Forums > Reports

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 04-22-2010, 05:22 AM
kmajors kmajors is offline Windows XP Access 2000 (version 9.0)
Novice
 
Join Date: Apr 2010
Posts: 5
kmajors is on a distinguished road
Default How to loop code to run through entire table

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
Reply With Quote
  #2  
Old 04-22-2010, 08:35 AM
pbaldy's Avatar
pbaldy pbaldy is online now Windows XP Access 2007 (version 12.0)
Who is John Galt?
 
Join Date: Feb 2010
Location: Nevada, USA
Posts: 1,500
pbaldy is on a distinguished road
Default

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.
__________________
Paul
MS Access MVP
www.BaldyWeb.com
Reply With Quote
  #3  
Old 04-22-2010, 08:55 AM
kmajors kmajors is offline Windows XP Access 2000 (version 9.0)
Novice
 
Join Date: Apr 2010
Posts: 5
kmajors is on a distinguished road
Default

Thanks for the reply.

However, I am very new to this and need help with the Else statement you talk about.
Reply With Quote
  #4  
Old 04-22-2010, 09:20 AM
pbaldy's Avatar
pbaldy pbaldy is online now Windows XP Access 2007 (version 12.0)
Who is John Galt?
 
Join Date: Feb 2010
Location: Nevada, USA
Posts: 1,500
pbaldy is on a distinguished road
Default

In pseudo code:

Code:
If Whatever Then
  set fields to not visible
Else
  set fields to visible
End If
__________________
Paul
MS Access MVP
www.BaldyWeb.com
Reply With Quote
  #5  
Old 04-22-2010, 11:53 AM
kmajors kmajors is offline Windows XP Access 2000 (version 9.0)
Novice
 
Join Date: Apr 2010
Posts: 5
kmajors is on a distinguished road
Default

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
Reply With Quote
  #6  
Old 04-22-2010, 12:04 PM
pbaldy's Avatar
pbaldy pbaldy is online now Windows XP Access 2007 (version 12.0)
Who is John Galt?
 
Join Date: Feb 2010
Location: Nevada, USA
Posts: 1,500
pbaldy is on a distinguished road
Default

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
__________________
Paul
MS Access MVP
www.BaldyWeb.com
Reply With Quote
  #7  
Old 04-22-2010, 12:51 PM
kmajors kmajors is offline Windows XP Access 2000 (version 9.0)
Novice
 
Join Date: Apr 2010
Posts: 5
kmajors is on a distinguished road
Default

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
Reply With Quote
  #8  
Old 04-22-2010, 12:56 PM
pbaldy's Avatar
pbaldy pbaldy is online now Windows XP Access 2007 (version 12.0)
Who is John Galt?
 
Join Date: Feb 2010
Location: Nevada, USA
Posts: 1,500
pbaldy is on a distinguished road
Default

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.
__________________
Paul
MS Access MVP
www.BaldyWeb.com
Reply With Quote
  #9  
Old 04-23-2010, 06:24 AM
kmajors kmajors is offline Windows XP Access 2000 (version 9.0)
Novice
 
Join Date: Apr 2010
Posts: 5
kmajors is on a distinguished road
Default

Great. The brackets were the trick. I am past that road block now. Thanks for all your help.
Reply With Quote
  #10  
Old 04-23-2010, 07:27 AM
pbaldy's Avatar
pbaldy pbaldy is online now Windows XP Access 2007 (version 12.0)
Who is John Galt?
 
Join Date: Feb 2010
Location: Nevada, USA
Posts: 1,500
pbaldy is on a distinguished road
Default

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!
__________________
Paul
MS Access MVP
www.BaldyWeb.com
Reply With Quote
Reply

Bookmarks

Tags
loop table, records, vba

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -8. The time now is 10:18 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.