Solved

How can i make the FindFirst Method Work ?

Posted on 1998-07-15
1
218 Views
Last Modified: 2012-06-27
I'm coding a search method in VBA to search in my databases's tables.  Here's my code :

Private Sub Ajouter_Article_Click()

    Dim dbspointeur As Database
    Dim rstpointeurEmprunts As Recordset
    Dim rstpointeurDetails As Recordset
    Dim rstpointeurArticles As Recordset
    Dim strcritere As String
    Dim strcritere2 As String
    Dim strReq As String
   
    Set dbspointeur = CurrentDb
   
    strReq = "SELECT * FROM Articles ORDER BY [Numéro d'entrée d'Article];"
    Set rstpointeurArticles = dbspointeur.OpenRecordset(strReq, dbOpenSnapshot)
   
    strReq = "SELECT * FROM Emprunts ORDER BY [No Emprunt];"
    Set rstpointeurEmprunts = dbspointeur.OpenRecordset(strReq, dbOpenSnapshot)
   
    strReq = "SELECT * FROM [Détails Emprunts] ORDER BY [No Détail];"
    Set rstpointeurDetails = dbspointeur.OpenRecordset(strReq, dbOpenSnapshot)
     
   
   strcritere = "[Section] =" & Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![Section] & " And [Sous-Section] =" & Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![Sous-Section] & " And [Type d'Information] =" & Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![Type d'Information] & " And [Numéro de Volume] =" & Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![No de Volume] & " And [Disponibilité] = True"

    strcritere2 = "[Section] =" & Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![Section] & " And [Sous-Section] =" & Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![Sous-Section] & " And [Type d'Information] =" & Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![Type d'Information] & " And [Numéro de Volume] =" & Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![No de Volume] & " And [Date Retour] = Null"
   
    rstpointeurArticles.FindFirst (strcritere)
    rstpointeurDetails.FindFirst (strcritere2)

   
    If (rstpointeurArticles.NoMatch = True) Then
        MsgBox "Can't rent book"
       
    ElseIf (rstpointeurDetails.NoMatch = False) Then
        MsgBox "Can't rent book ! "
                 
         
        Else
             
            rstpointeurArticles![Disponibilité] = False
           
            If NombreFoisClique = 0 Then
           
                With rstpointeurEmprunts
                    .AddNew
                    ![No Membre] = Forms![Nouvel Emprunt]![No Membre]
                    ![No Employé] = Forms![Nouvel Emprunt]![No Employé]
                    ![Date Départ] = Date
                    .Update
                End With
                rstpointeurEmprunts.Close
                NombreFoisClique = 1
               
                With rstpointeurDetails
                    .AddNew
                    ![No Emprunt] = Forms![Nouvel Emprunt].[No Emprunt]
                    ![Section] = Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![Section]
                    ![Sous-Section] = Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![Sous-Section]
                    ![Type d'Information] = Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![Type d'Information]
                    ![Numéro de Volume] = Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![No de Volume]
                    ![Date Retour] = Null
                End With
           
                rstpointeurDetails.Update
                rstpointeurDetails.Close
               
               
            Else
           
                With rstpointeurDetails
                    .AddNew
                    ![No Emprunt] = Forms![Nouvel Emprunt].[No Emprunt]
                    ![Section] = Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![Section]
                    ![Sous-Section] = Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![Sous-Section]
                    ![Type d'Information] = Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![Type d'Information]
                    ![Numéro de Volume] = Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![No de Volume]
                    ![Date Retour] = Null
                    .Update
                End With
                rstpointeurDetails.Close
             
            End If
        End If
   


End Sub

The structure of the table "Articles" is : No Article, Section, Sous-Section, Type d'Information, Numéro de Volume, Titre, Auteur , ...

The structure of the table "Détails emprunts" is : No Detail, No Emprunt, Section  , Sous-Section, Type dINformation, Numéro de Volume, Date Retour

The Structure of the table "Emprunts" is : No Emprunt, No Membre, No Employé, Date Départ.

As you can see , this procedure is for a library, to rent a book and enter the transaction in tables.
However , my "FindFirst" method gives me error 3070, that it doesn't recognize the value of my form's fields as a valid field name or expression.

How can i make this FindFirst Work ?
0
Comment
Question by:soleil_18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
Helicopter earned 50 total points
ID: 1976755
If your fields are text fields they must have a '.....' surrounding them


e.g.

"[Section] ='" & Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![Section] & "'  And [Sous-Section] ='" & Forms![Nouvel Emprunt]![Sous-Formulaire des Articles a Emprunter]![Sous-Section]& "'"

assuming these 2 form fields are text

I suggest you break the code just before the find first statement and have a look at the value of strcriteria to make sure the string makes sense.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question