Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185

    Question Unanswered: Bind Unbound Form to ADO recordset

    Hi,
    Its long time I had no post here, but I always read the threads.
    I have a search form which user can select several search criteria and the resault of search will be passed to another form name Report1 which user can select those records which are near to his opinion.
    In order to prevent having a very big SQL statement for search form, I decided to use recordset filter based on selected criteria in search form by user.
    up to this point there is no problem but when I want to bind the recordset to Report1 it give the runtime error No. 5 Invalid Procedure Call or Argument.
    here is the code on opening the Report1 formthe form is continous form)
    Code:
    Private Sub Form_Open(Cancel As Integer)
    
    Dim objConn As ADODB.Connection
    Dim objRST As ADODB.Recordset
    Dim SQL1 As String
    Dim frmForm As New Form
    
    Set objConn = CurrentProject.Connection
    Set objRST = New ADODB.Recordset
    Set frmForm = [Forms]![Report1]
    
    SQL1 = "SELECT Main.*, Vahed.* FROM Main INNER JOIN Vahed ON Main.ID = Vahed.IDMain;"
    
    objRST.Open SQL1, objConn, adOpenKeyset, adLockOptimistic
    
    objRST.Filter = "Category = '" & [Forms]![Search1]![Category] & "'"
    objRST.Filter = "Type = '" & [Forms]![Search1]![Type] & "'"
    objRST.Filter = "Mantaghe = '" & [Forms]![Search1]![Mantaghe1] & "'"
    
    Set Me.Recordset = objRST ' THIS LINE CAUSE THE ERROR
    
    objRST.Close
    Set objConn = Nothing
    Set objRST = Nothing
    End Sub
    I searched the msdn and some programming books and the method for all of them is : Set me.recordset=objRST
    I may load a refrence or something?
    Thanks
    Last edited by Aran1; 11-03-09 at 03:15.
    <<Never Walk on the Traveled Path, Because it only Leads you to where the Others have been.>>
    Graham Bell

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Apply the filter on the form after assigning the recordset to it :
    Code:
    Set Me.Recordset = objRST
    Me.Filter = "Category = '" & [Forms]![Search1]![Category] & "'"
    Have a nice day!

  3. #3
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185
    I didin't think it is as simple as that, thanks.
    but tehere is still a problem it doesn't apply the filter I mean the code runs without error but the records shown in form are not filtered.
    <<Never Walk on the Traveled Path, Because it only Leads you to where the Others have been.>>
    Graham Bell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •