Mega brain buster for me :(

bensmeets

Registered User.
Local time
Today, 18:14
Joined
Mar 21, 2003
Messages
49
Hi, I could really use some help cause i am going crazy. I have a form with multiple subforms.

Behind one of the subforms i have this code:
Code:
Private Sub Form_Current()
    Dim taak_id As Integer
    Dim rcs As DAO.Recordset
    Dim s As String
    taak_id = Me.taak_fk
    Me.Parent.Form.currenttaak.Value = Me.taak_fk
    sessie_fk = Me.Parent.sessie_id
    If Me.Parent.VA_Subform___tijden_per_taak.Form.IsLoaded Then
        Set rcs = Me.Parent.VA_Subform___tijden_per_taak.Form.RecordsetClone
        s = "[taak_fk]=" & Str(taak_id) & " AND [sessie_fk]=" & Str(sessie_fk) & ""
        rcs.FindFirst s
        If rcs.NoMatch = True Then 'niet gevonden
            rcs.AddNew
        Else
            Me.Parent.VA_Subform___tijden_per_taak.Form.Bookmark = Me.Parent.VA_Subform___tijden_per_taak.Form.RecordsetClone.Bookmark
            Me.Parent.Mediaplayer.currentPosition = Parent.VA_Subform___tijden_per_taak.Form.start
        End If
        rcs.Close
    End If

    
End Sub

If Me.Parent.VA_Subform___tijden_per_taak.Form.IsLoaded Then

This row gives the problem. On switching of rows in subform 1 there hase to be an action done on SF 2. It works but the error is that when i open the form for the first time it says that it cannot do stuff with the rcs recordset. I am guessing because the SF2 is not rendered yet and so not questionable. When i skip the error , everything seems to work fine. So i figured that i should check if SF2 exists before trying to clone it. I have tried several ways but none seems to work. Anyone? tnx in advance.

Ben
 
Ben,

Try using Forms!MainForm!Subform2.Form.HasData to determine if the subform has an empty recordset. A form IsLoaded whether it has records or not.

hth

Gerhard
 
tnx but i couldn't get it to work. Keeps popping up runtime errors saying it can't locate the subform (i did change it to my situation but no help).

Is there a way to surpress the runtime errors? Cause after i click the error away, everything works fine?
 
Could you post the code you're using, and what level is the subform on? Main->Sub1 or Main->Sub1->Sub2 or anything else?
 
Code:
Private Sub Form_Current()
    Dim taak_id As Integer
    Dim rcs As DAO.Recordset
    Dim s As String
    taak_id = Me.taak_fk
    Me.Parent.Form.currenttaak.Value = Me.taak_fk
    sessie_fk = Me.Parent.sessie_id
    [COLOR=red]Set rcs = Me.Parent.VA_Subform___tijden_per_taak.Form.RecordsetClone[/color]
    s = "[taak_fk]=" & Str(taak_id) & " AND [sessie_fk]=" & Str(sessie_fk) & ""
    rcs.FindFirst s
    If rcs.NoMatch = True Then 'niet gevonden
        rcs.AddNew
    Else
        Me.Parent.VA_Subform___tijden_per_taak.Form.Bookmark = Me.Parent.VA_Subform___tijden_per_taak.Form.RecordsetClone.Bookmark
        Me.Parent.Mediaplayer.currentPosition = Parent.VA_Subform___tijden_per_taak.Form.start
    End If
    rcs.Close
  
End Sub

This is the code. Red line is the error line. The subform is on level 1. So inside 1 other form. That form is the main. From out this subform i need to adress another subform on main.

Hope this helps..tnx in advance.
 
I've tried the HasData in a sample db, but I don't get it to work as it should. I've used it successfully in a report, through a query though.

I don't know if you can create a recordset the way you do when your outside the form you want to clone. I would rather run a SQL statement to create the recordset, and check the EOF property to see if it's empty.

This I know will work.


Gerhard
 
ke, i will go and check it all out. Tnx alot for the effort m8!
 

Users who are viewing this thread

Back
Top Bottom