Mainform and multiple subforms search...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #16
    Originally posted by lovelydan
    NeoPa
    Code:
    Private Sub cmbMinistryName_AfterUpdate()
    Dim strFilter As String
      
        ' This assumes Handle is a text field
        strFilter = "subform![minname] LIKE '" & Me.cmbMinistryName & "*'"
        Me.SubForm.Form.Filter = strFilter
        Me.SubForm.Form.FilterOn = True
    
    End Sub
    The above code does not give me an error but it returns the sub form with no records as if i called the gotoAddNewRec command.

    i tried both of the codes above then i also tried the following:
    Code:
    Dim strFilter as string
    
    if me!cmbMinistryName >"" Then
         strFilter = strFilter & _
         " AND ([minName]) = " & _
         me!cmbMinistryName & ")"
    
           me.subform.form.recordsource = strFilter
          ' me!Subform.form.filterOn=True
    end if
    
    end sub
    This code gives me the following error:

    The record source ' and([minName]) ' specified on this form or report does not exist.

    Run-time error '2580'


    i hope this will make senses to you...

    regards...lovel ydan
    Both sets of code are unentered (not taken from your project). Please ensure that you enter the code into your project first before copying it in here. You're clearly not experienced enough to type straight from your head and get it in a reliable form, and this can waste a lot of our time (and ultimately yours too of course). Furthermore, I asked you to post what you're currently using. As this is just some stuff you've typed out it is clearly not what was requested. However, I'll comment on what's here as it may even help (I can certainly see some problems with it).

    Your first bit of code is mainly comment lines, so that can be ignored.

    The second bit is trying to set the filter relative to the form though. This is a misunderstandin g. It needs to refer to the recordsource that the form is built on (bound to). Generally though, it can remain unqualified (See suggested code below). It also needs a .Requery when it's set (I believe). If the field in the recordsource is [MinName], then it should be something like :
    Code:
    Private Sub cmbMinistryName_AfterUpdate()
    Dim strFilter As String
      
        With Me.SubForm.Form
            ' This assumes Handle is a text field
            strFilter = "[MinName] Like '" & Me.cmbMinistryName & "*'"
            .Filter = strFilter
            .FilterOn = True
            Call .Requery
        End With
    
    End Sub
    In the second bit of code you're setting the record source to the Filter value. This makes no sense.

    Try the suggested code and see what you get.
    Last edited by NeoPa; Apr 30 '09, 12:36 PM. Reason: End With line was missing.

    Comment

    • lovelydan
      New Member
      • Mar 2009
      • 50

      #17
      NeoPa

      i have used this example the way it is from your first suggestion about "example Filtering a form"

      it also does not give an error but it returns the subform with no records...

      hey sorry bout unentered codes...im using 2 computers, the laptop im using for programming is not connected to the internet/network but the other PC is and it does not have applications i need for my day to day work so im sorry for that, will try something better next tym.

      regards, LovelyDan(Afric a-Botswana)

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #18
        That sounds like a good reason Dan. It's unfortunate, but understandable.

        Let me add a tip that I couldn't find yesterday. This may help you, but also anyone else reading the thread.
        Originally posted by NeoPa
        It is always a good idea to ensure that variable name checking is enabled, AND your code compiles (at least compilation has been attempted), before submitting a question.

        This avoids asking questions which are much more easily resolved on your own PC than on a forum.

        To ensure variable name checking is enabled for all new modules, go to - Tools / Options / Editor (from the VBA Editor window) and set Require Variable Declaration to True (checked). For existing modules, ensure that the Option lines at the very top include :
        Code:
        Option Explicit
        To compile your project, select (again from the VBA Editor window) Debug / Compile Project Name.

        We ARE generally happy to help with compilation problems too (If you find an error reported and you can't resolve it, let us know), but we do expect members to have tried compiling before submitting a question. That way we have a better idea of the sort of problem we're looking at.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #19
          Originally posted by lovelydan
          I have used this example the way it is from your first suggestion about "example Filtering a form"

          it also does not give an error but it returns the subform with no records...
          I'm not sure if this means you've tried my latest suggestion or not?

          Comment

          • lovelydan
            New Member
            • Mar 2009
            • 50

            #20
            NeoPa;

            Yah, i have tried your latest i even found out that the "End with" was missing..

            my regards,

            Comment

            • lovelydan
              New Member
              • Mar 2009
              • 50

              #21
              NeoPa

              eeeeeeyeyeyeye, ayayayayaya!! trouble is begining to start after i ran a few things you suggested and debug i got an error..and now the db can not open the welcome sourceObject subform...im still copying the whole code from my laptop and in few seconds i will paste it... i think im seeing dust now, but i wont give up

              im realy thankful 4 ur help guys!

              regards..lovely daniell

              Comment

              • lovelydan
                New Member
                • Mar 2009
                • 50

                #22
                NeoPa
                Code:
                Option Compare Database
                Option Explicit
                
                Dim iBackupFrequency As Integer
                
                '<@STRINGRESOURCE MODULE="DHIS_CORE.mdb/Form_BackupReminderOptions"> - Do not edit by hand
                [B]Private srRes1 As New StringResource[/B]   ' For loading resource strings
                Private Const strBackupAccordingToGlobalOptionsCaption As Long = 5081
                Private Const strBackupReminderNextTimeUserQuitDHISCaption As Long = 5082
                Private Const strRunBackupCaption As Long = 5077
                Private Const strSkipAndSwitchOffReminderTillNextMonthCaption As Long = 5079
                Private Const strSkipBackupUntilNextCaption As Long = 5076
                Private Const strThisWillSkipTheBackupReminderFor1Caption As Long = 5080
                '</@STRINGRESOURCE>
                
                Private Sub Form_Load()
                On Error GoTo ErrHandler
                
                    If g_bMultiLanguageActivated Then InitialiseMLstrings
                
                    fmBackupOptions_AfterUpdate
                
                ExSub:
                    Exit Sub
                ErrHandler:
                    MsgBox Err.Description
                    Resume ExSub
                
                End Sub
                
                Sub InitialiseMLstrings()
                
                    Dim sPeriodType As String
                
                    Me.lblSkipBackupThisPeriod.Caption = srRes1(strSkipBackupUntilNextCaption)
                
                    iBackupFrequency = GetDataFileProperty("BackupProcedureFrequency", "EntryNumber")
                
                    Select Case iBackupFrequency
                        Case 1
                            sPeriodType = srGlobal(strGDayCaption)
                        Case 2
                            sPeriodType = srGlobal(strGWeekCaption)
                        Case 3
                            sPeriodType = srGlobal(strGMonthCaption)
                    End Select
                
                    Me.lblSkipBackupThisPeriod.Caption = Me.lblSkipBackupThisPeriod.Caption & " " & sPeriodType
                
                   Me.fmBackupOptions.StatusBarText = ""
                   Me.fmBackupOptions.ControlTipText = ""
                   Me.optRun.StatusBarText = ""
                   Me.optRun.ControlTipText = ""
                   Me.lblRunBackup.Caption = srRes1(strRunBackupCaption)
                   Me.optSkipNow.StatusBarText = ""
                   Me.optSkipNow.ControlTipText = ""
                   Me.lblSkipBackupThisSession.Caption = srGlobal(strGSkipCaption)
                   Me.optSkipTillNextPeriod.StatusBarText = ""
                   Me.optSkipTillNextPeriod.ControlTipText = ""
                   Me.lblSkipBackupThisPeriod.Caption = srRes1(strSkipAndSwitchOffReminderTillNextMonthCaption)
                   Me.cmdOK.Caption = srGlobal(strGContinueString)
                   Me.lblDescription.Caption = ""
                
                End Sub
                
                Private Sub fmBackupOptions_AfterUpdate()
                On Error GoTo ErrHandler
                
                    Select Case Me.fmBackupOptions
                    
                        Case 1
                            Me.lblRunBackup.FontBold = -1
                            Me.lblSkipBackupThisPeriod.FontBold = 0
                            Me.lblSkipBackupThisSession.FontBold = 0
                            Me.lblDescription.Caption = srRes1(strBackupAccordingToGlobalOptionsCaption)
                        Case 2
                            Me.lblRunBackup.FontBold = 0
                            Me.lblSkipBackupThisPeriod.FontBold = 0
                            Me.lblSkipBackupThisSession.FontBold = -1
                            Me.lblDescription.Caption = srRes1(strBackupReminderNextTimeUserQuitDHISCaption)
                        Case 3
                            Me.lblRunBackup.FontBold = 0
                            Me.lblSkipBackupThisPeriod.FontBold = -1
                            Me.lblSkipBackupThisSession.FontBold = 0
                            Select Case iBackupFrequency
                                Case 1
                                    Me.lblDescription.Caption = srRes1(strThisWillSkipTheBackupReminderFor1Caption) & " " & srGlobal(strGDayCaption)
                                Case 2
                                    Me.lblDescription.Caption = srRes1(strThisWillSkipTheBackupReminderFor1Caption) & " " & srGlobal(strGWeekCaption)
                                Case 3
                                    Me.lblDescription.Caption = srRes1(strThisWillSkipTheBackupReminderFor1Caption) & " " & srGlobal(strGMonthCaption)
                            End Select
                            
                    End Select
                
                ExSub:
                    Exit Sub
                ErrHandler:
                    MsgBox Err.Description
                    Resume ExSub
                
                End Sub
                
                Private Sub cmdOK_Click()
                On Error GoTo ErrHandler
                
                    If Me.fmBackupOptions = 1 Then
                        RunBackupProcedure
                    ElseIf Me.fmBackupOptions = 3 Then
                        SetDataFileProperty "DateOfLastBackupProcedure", "EntryDate", "#" & Now() & "#"
                    End If
                
                    DoEvents
                
                    DoCmd.Close acForm, Me.Name, acSaveNo
                
                ExSub:
                    Exit Sub
                ErrHandler:
                    MsgBox Err.Description
                    Resume ExSub
                
                End Sub
                here is the code with an error and it points to the first bold line
                message is; user-defined type not defined.

                and the when i close and try to open the DB i get the following message as it tries to load the subform

                message; method "form' of object' _subform failed

                if the is a way to send you a sample of my DB please let me knw. the DB is smaller than 1MB. and only has four forms

                regards, lovely
                Last edited by NeoPa; Apr 30 '09, 12:46 PM. Reason: Please use the [CODE] tags provided

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32633

                  #23
                  I think I will need to see your RecordSource then.
                  Is [MinName] even a field in there?
                  Originally posted by lovelydan
                  ...i even found out that the "End with" was missing.
                  Good spot. I even mucked up the indenting horribly. Sorry about that.
                  I've fixed that in the original now.

                  Comment

                  • lovelydan
                    New Member
                    • Mar 2009
                    • 50

                    #24
                    NeoPa
                    Code:
                    Sub SetActiveFormLabel()
                    
                    'This will set the "title" of the form using the "Assets" form caption
                       [B] If Len(Nz(Me.SubForm.Form.Caption, "")) > 0 Then[/B]
                            Me.lblSubFormTitle.Caption = Me.SubForm.Form.Caption
                        Else
                            On Error Resume Next
                            Me.lblSubFormTitle.Caption = Screen.ActiveControl.Caption
                            On Error GoTo 0
                        End If
                    
                        Me.Caption = Me.lblSubFormTitle.Caption
                        
                    End Sub
                    the first error message comes from this code...

                    message is; method "form' of object '_ subform' failed

                    regards..lovely
                    Last edited by NeoPa; Apr 30 '09, 12:59 PM. Reason: Please use the [CODE] tags provided

                    Comment

                    • ChipR
                      Recognized Expert Top Contributor
                      • Jul 2008
                      • 1289

                      #25
                      Is SubForm actually the name of your subform control?

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32633

                        #26
                        Originally posted by lovelydan
                        here is the code with an error and it points to the first bold line
                        message is; user-defined type not defined.
                        I can't help much here. I don't know what a StringResource object is. It's not standard Access as far as I'm aware.

                        I can only assume (as the compiler has) that it is a user-defined class. You need to ensure that it is defined somewhere, and that if it is outside of your project, then a Reference exists for it.
                        Originally posted by lovelydan
                        and the when i close and try to open the DB i get the following message as it tries to load the subform

                        message; method "form' of object' _subform failed
                        This looks like you have saved the project without trying to compile it. This is not a good idea. See post #18 for how to ensure the basics are done before posting. It is also a good idea to follow these steps when developing a database.
                        Originally posted by lovelydan
                        if the is a way to send you a sample of my DB please let me knw. the DB is smaller than 1MB. and only has four forms
                        To attach items to one of your posts you need to scroll down the page a little when posting (either originally or in an advanced edit screen) to the button that saya Manage Attachments. Pressing on that leads you to a page where you can add or remove your attachments. It also lists the maximum file sizes for each of the allowed file types.

                        For a database, please ensure you do a Compact & repair on it first, before ZIPping it into a .ZIP file. Only attach this .ZIP file.

                        Comment

                        • lovelydan
                          New Member
                          • Mar 2009
                          • 50

                          #27
                          sory for the wrong way of posting im not yet familier with how im surpose to paste the codes...

                          Comment

                          • NeoPa
                            Recognized Expert Moderator MVP
                            • Oct 2006
                            • 32633

                            #28
                            Originally posted by lovelydan
                            NeoPa
                            Code:
                            Sub SetActiveFormLabel()
                            
                            'This will set the "title" of the form using the "Assets" form caption
                               [B] If Len(Nz(Me.SubForm.Form.Caption, "")) > 0 Then[/B]
                                    Me.lblSubFormTitle.Caption = Me.SubForm.Form.Caption
                                Else
                                    On Error Resume Next
                                    Me.lblSubFormTitle.Caption = Screen.ActiveControl.Caption
                                    On Error GoTo 0
                                End If
                            
                                Me.Caption = Me.lblSubFormTitle.Caption
                                
                            End Sub
                            the first error message comes from this code...

                            message is; method "form' of object '_ subform' failed

                            regards..lovely
                            There is no .Caption property for a Form control as far as I'm aware. What are you trying to reference with this line of code?

                            NB. Please remember that using the [ CODE ] tags is not optional. Please ensure all further posts have all code posted in the tags. Thank you.

                            Comment

                            • NeoPa
                              Recognized Expert Moderator MVP
                              • Oct 2006
                              • 32633

                              #29
                              CODE TAGS

                              To add the tags simply select the code part of your post, then click on the button that looks like a hash (#).

                              Comment

                              • lovelydan
                                New Member
                                • Mar 2009
                                • 50

                                #30
                                NeoPa

                                if u go to form properties in design view under format u will find caption...whate ver name typed there, there code picks it and throws the name into the unbound subform lbl for caption...it works

                                Comment

                                Working...