none
Method or Data member not found

    Question

  • Hello I'm getting the error message "Method or data member not found". This happens with a form that I'm working on in Access. The form is used to search the database for records matching a name that is entered into a text box. Here is the code in VBA if it is any help:

    Option Compare Database
    Private Sub RefreshSearch()
    Me.chkDoSearch.Value = True
    Me.FarmerSearchbyName_subform.Requery
    Me.FarmerSearchbyName_subform.SetFocus
    End Sub
    Private Sub btnNewSearch_Click()
    With Me.txtLookup
                .SetFocus
            .SelStart = 0
            .SelLength = Len(.Text)
        End With
    End Sub

    Private Sub btnOk_Click()
    If Me.FarmerSearchbyName_subform.CurrentRecord > 0 Then    <-------------- This is where the error message is generated
    Me.Tag = Me.FarmerSearchbyName_subform.Form.Recordset("FarmerID")
    Me.Visible = False
    End Sub

    Private Sub btnSearch_Click()
    RefreshSearch
    End Sub

    Private Sub chkIncludeInactive_AfterUpdate()
      RefreshSearch
    End Sub
    Private Sub Form_Activate()
        Me.Tag = ""
    End Sub

    Private Sub Form_Load()
        Me.Tag = ""
    End Sub

     

    Sunday, August 08, 2010 10:18 PM

All replies

  • Try adding referenc to the Subfors Form as :

     Me.FarmerSearchbyName_subform.Form.CurrentRecord

    Sunday, August 08, 2010 11:36 PM
  • Well, in earlier versions of Access (2003 and earlier) the subform's FORM object itself could wind up being NULL if the query from the parent form's data resulted in NO valid records.

    In that circumstance, referencing to subform's properties and objects could result in 438 errors and "method or data member not found" sorts of errors. Is it possible that in your situation you are getting into data results where the subform could contain no data?

    I generally code those lines more defensively to detect and adjust to the "no data / no valid subform FORM object" cases without throwing those types of error messages.

    i.e.

    Private Sub btnOk_Click()

    dim oFM as form_mySubFormNameHere

    set ofm = Me.FarmerSearchbyName_subform.form

    if not ofm is nothing then
      If ofm.CurrentRecord > 0 Then    <-------------- This is where the error message is generated
        me.Tag = Me.FarmerSearchbyName_subform.Form.Recordset("FarmerID")
        Me.Visible = False

      end if

    'else  react accordingly...

    end if
    End Sub

    Monday, August 09, 2010 2:34 AM
  • I now get an empty page. What could cause this? There is no error message

    Monday, August 09, 2010 3:10 AM
  • duplicate the query for the subform in the query designer an manually input the data values from the parent form (as filters in the query).

    Chances are that you will get no data records - having the child form display as blank is the MS-defined correct default behavior for "empty" Access subforms (at least those where adding new records is not permitted).

    I will usually hide the subform control in the " 'else  react accordingly" code area and display some sort of warning text (a label control, usually hidden behind the nornally displayed subform control) about having no data to display (and perhaps showing a control button to add data as required/permitted by the business rules for the system).

    I often put this type of code in the form_current event for the parent form to toggle the display of the appropriate controls depending upon whether the subform has data to display/edit or not.

    Monday, August 09, 2010 3:29 AM
  • Hi Shawn,
     
    This is unrelated to your question, but I notice you don't have Option Explicit set. You should set that statement and declare all variables, otherwise you can run into unexpected results.
     

    Hello I'm getting the error message "Method or data member not found". This happens with a form that I'm working on in Access. The form is used to search the database for records matching a name that is entered into a text box. Here is the code in VBA if it is any help:

    Option Compare Database
    Private Sub RefreshSearch()
    Me.chkDoSearch.Value = True
    Me.FarmerSearchbyName_subform.Requery
    Me.FarmerSearchbyName_su bform.SetFocus
    End Sub
    Private Sub btnNewSearch_Click()
    With Me.txtLookup
             &nb sp;  .SetFocus
            .SelStart = 0
            .SelLength = Len(.Text)
        End With
    End Sub

    Private Sub btnOk_Click()
    If Me.FarmerSearchbyName_subform.CurrentRecord > 0 Then    <-------------- This is where the error message is generated
    Me.Tag = Me.FarmerSearchbyName_subform.Form.Recordset("FarmerID")
    Me.Visible = False
    End Sub

    Private Sub btnSearch_Click()
    RefreshSearch
    End Sub

    Private Sub chkIncludeInactive_AfterUpdate()
      RefreshSearch
    End Sub
    Private Sub Form_Activate()
        Me.Tag = ""
    End Sub

    Private Sub Form_Load()
        Me.Tag = ""
    End Sub

     


    Regards, Graham R Seach Microsoft Access MVP Sydney, Australia
    Monday, August 09, 2010 4:58 AM
  • I'm not quite sure what you mean. Could you elaborate a little more please?
    Thursday, August 12, 2010 5:49 AM