Loop through all records in a continuous form and do stuff (1 Viewer)

sambo

Registered User.
Local time
Today, 00:47
Joined
Aug 29, 2002
Messages
289
I would like to loop through all of the records on a subform as soon as a button on the MainForm is clicked.

Something like this:

Code:
Private Sub PassBut_Click()

   'MsgBox Forms!frmCategory!frmSubCategorySub.Form.CurrentRecord & vbCrLf & _
     Forms!frmCategory!frmSubCategorySub!txtCategory & vbCrLf & "Pass"
     
With Forms!frmCategory!frmSubCategorySub.Form

  DoCmd.GoToRecord , , acFirst
  
  Do
     If Forms!frmCategory!frmSubCategorySub!PassFail = -1 Then
       MsgBox Forms!frmCategory!frmSubCategorySub!txtCategory & " Pass"
     Else
       MsgBox Forms!frmCategory!frmSubCategorySub!txtCategory & " Fail"
     End If
  DoCmd.GoToRecord , , acNext
  Loop
  
End With
     
End Sub

I am trying to look at the status of each PassFail Field in my subform and manipulate that field based on the Yes/No Value.

Suggestions..
 

Travis

Registered User.
Local time
Today, 00:47
Joined
Dec 17, 1999
Messages
1,332
Set a RecordSet Object = the Subforms RecordSet

Code:
Set rstSubForm=Forms!frmCategory!frmSubCategorySub.Form.RecordSet

Then loop through it and manipulate.  

Do While not rstSubForm.EOF

   rstSubForm.MoveNext
Loop
 

sambo

Registered User.
Local time
Today, 00:47
Joined
Aug 29, 2002
Messages
289
Manipulating the image source according to yes/no

Now that I am looping through all records. I would like to change an image source depending on a yes/no box.

Something like this:

Code:
Do While Not rstSubForm.EOF

          If Forms!frmCategory!frmSubCategorySub!PassFail = -1 Then
            MsgBox Forms!frmCategory!frmSubCategorySub!txtCategory & " Pass"
            Forms!frmCategory!frmSubCategorySub!myImage.Source = "C:\myPics\PassPic.bmp"
            'Forms!frmCategory!frmSubCategorySub!StatusBox.Caption = "P"
          Else
            MsgBox Forms!frmCategory!frmSubCategorySub!txtCategory & " Fail"
            Forms!frmCategory!frmSubCategorySub!myImage.Source = "C:\myPics\FailPic.bmp"
            'Forms!frmCategory!frmSubCategorySub!StatusBox.Caption = "F"
          
          End If
             rstSubForm.MoveNext
Loop

The !myImage.Source = "C:\myPics\FailPic.bmp" Line does not work. I'm not sure how to make it work either.

The scheme is...
If the record is in Status, "PASS", then insert a "PASS" image for that record.
So 3 records may have a "PASS" image while the other 2 have a "FAIL" image.

Help..
 

sambo

Registered User.
Local time
Today, 00:47
Joined
Aug 29, 2002
Messages
289
Updated Problem

I changed my approach a little bit. I embedded the images that I will be using in a pre-existing table in my db.
Now if I want to use a picture I just go get it from the table.

Here is my new problem...
I can get the object (bitmap image) in code, but I am having a hard time updating the image source in my continuous form accordingly.

Here is my code so far...

Code:
Private Sub PassBut_Click()
Dim rstSubForm As DAO.Recordset
Dim picToGet As Object
Dim db As DAO.Database, rst As DAO.Recordset
Dim strSearch As String

'Get the proper recordset
Set rstSubForm = Forms!frmCategory!frmSubCategorySub.Form.Recordset


'If end of Recordset, don't continue
If rstSubForm.EOF = True Then Exit Sub

  'PassFail Field is a checkbox
  If Forms!frmCategory!frmSubCategorySub!PassFail = -1 Then   'A pass
      MsgBox Forms!frmCategory!frmSubCategorySub!txtCategory & " Pass"
    Set db = CurrentDb
    Set rst = db.OpenRecordset("Pictures", dbOpenSnapshot)
      With rst
        'Get the proper picture (A Pass Picture stored in another table)
        .FindFirst "PicName = 'Pass'"
         Set picToGet = !PicObj   'Get the current record's picture
      End With
    rst.Close
    db.Close
    
    'Set the Field on the Continuous Form to the proper Picture (taken from above code)
    rstSubForm!PassFailPic = picToGet
  Else  'A fail
            MsgBox Forms!frmCategory!frmSubCategorySub!txtCategory & " Fail"
          
  End If
rstSubForm.MoveNext

End Sub

Disregard the Else section of the If statement. I am just focusing on the "If" part right now.

My problem comes when I try to set the value of the !PassFailPic image. I am trying to set the object source according to whether or not the current record is a pass or a fail.

I get this error message...
"Object Invalid or No Longer Set"

Help..
 

Users who are viewing this thread

Top Bottom