Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2008

    Unanswered: Problems with FindFirst Method

    I've been improving a database and i would like to add a new functionality.
    I have the following tables:
    Carteira, Compras, Vendas...

    I have a main form where i can see the information recorded in those tables. Main form gets the data from table Carteira but i also have subforms in the main form to see the information of the others tables. I want to build a new form that allows me to insert new data into the table Compras. The idea is when i press a button, this new form will appear, then i will insert the data press another button that will record the introduced data into table Compras. Bellow i describe the table fields.
    Table Carteira has the fields: Referencia,nome,quantidade,total...
    Table Compras has the fields: Referencia, Ref_compra,data,quantidade,total

    I've created the following Sub. The goal would be to record the introduced data into table Compras:

    Private Sub Comprar()
    Dim DB As DAO.Database
    Dim rstCarteira, rstCompras As DAO.Recordset
    Dim strSQL As String

    Set DB = CurrentDb
    Set rstCarteira = DB.OpenRecordset("Carteira")
    Set rstCompras = DB.OpenRecordset("Compras")

    strSQL = "[Ref_compra] =' " & Me.Texto6 & "'"

    MsgBox strSQL

    With rstCompras
    .FindFirst (strSQL)

    If .NoMatch Then
    MsgBox "No Match was found."
    MsgBox "It worked!"
    End If
    End With

    Set rstCompras = Nothing
    Set rstCarteira = Nothing
    Set DB = Nothing

    End Sub

    When i execute the code i have the following error:
    Run-time error '3251'
    Operation not supported for this type of object

    The debuger points to the line ".FindFirst (strSQL)"

    What seems to be the problem???

  2. #2
    Join Date
    Jun 2005
    Richmond, Virginia USA
    Provided Answers: 19
    Try replacing

    strSQL = "[Ref_compra] =' " & Me.Texto6 & "'"


    strSQL = "[Ref_compra] = '" & Me.Texto6 & "'"

    I've seen not having a space between the equal sign and the first, single quotation mark cause an error before. I'd copied someone else's code to try and debug it for them, and it drove me bonkers until I noticed the lack of a space!
    Hope this helps!

    The problem with making anything that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    May 2005
    Nevada, USA
    Provided Answers: 6
    The Find methods are not supported for all recordsets. It would be much more efficient to open your recordset on an SQL statement that only pulled the appropriate records, rather than opening the entire table and then finding them.

  4. #4
    Join Date
    Jun 2008
    Thank you all... the line strSQL = "[Ref_compra] = '" & Me.Texto6 & "'" solve the problem. Now it's working ok. Thanks

Posting Permissions

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