SQL query VBA Access issue -


i error when try execute code, think have problem in sql query , line "service = dlookup ..." can please ! thank much

    private sub btnconnexion_click()      dim categ integer     dim service string     dim idprof integer      dim db dao.database     dim qdf dao.querydef     dim strsql string     set db = currentdb       'vérification que l'utilisater bien entrer e login et le mot de passe     me.txtlogin.setfocus     if isnull(me.txtlogin)     msgbox "svp entrer votre login ", vbinformation, "login required "     me.txtlogin.setfocus     elseif isnull(me.txtmdp)     msgbox "svp entrer votre mots de passe ", vbinformation, "mdp required "     me.txtmdp.setfocus     else     'vérification que le login et le mdp sont corrects     if (isnull(dlookup("login", "dbo_authentification", "login='" & me.txtlogin.value &       "'"))) or _         (isnull(dlookup("mdp", "dbo_authentification", "mdp='" & me.txtmdp.value & "'")))            msgbox "login ou mdp incorrect"     else     'récupération de l'idcatégorie dans categ, pour préciser les sessions des acteurs selon   leurs catégories professionneles         categ = dlookup("idcategorie", "dbo_professionnel", "idprofessionnel = " &   dlookup("idcompte", "dbo_authentification", "login='" & me.txtlogin.value & "'"))         'docmd.close         if categ = 3             docmd.openform "role"             else             docmd.openform "listingpatients"              'service récupère le service du professionnel authentifié pour l'afficher à   l'entete du formulaire "listingpatients"             service = dlookup("intituleserv", "dbo_service", "idservice = " &   dlookup("idprofessionnel", "dbo_professionnel", "idprofessionnel = " & dlookup("idcompte",   "dbo_authentification", "login='" & me.txtlogin.value & "'")))             forms![listingpatients]![txtintituleserv] = service                strsql = "select dbo_patient.*, dbo_service.intituleserv, dbo_hospitalisatacuelle.lit, dbo_professionnel.idprofessionnel, dbo_hospitalisatacuelle.dateentree, dbo_hospitalisatacuelle.datesortie dbo_service inner join ((dbo_professionnel inner join dbo_authentification on dbo_professionnel.idprofessionnel = dbo_authentification.idcompte) inner join (dbo_patient inner join (dbo_hospitalisatacuelle inner join dbo_donneepatientactuelles on dbo_hospitalisatacuelle.idhosp = dbo_donneepatientactuelles.idhosp) on dbo_patient.idpatient = dbo_donneepatientactuelles.idpatient) on dbo_professionnel.idprofessionnel = dbo_hospitalisatacuelle.idprofessionnel) on dbo_service.idservice = dbo_professionnel.idservice (((dbo_hospitalisatacuelle.dateentree)<=now()) , ((dbo_hospitalisatacuelle.datesortie)>now())) or (((dbo_hospitalisatacuelle.datesortie) null) , dbo_service.intituleserv = '" & service & "') ;"         end if     end if    end if      end sub 

so when execute code error "invalid use of null" in line "service = ..." , sql query dosen't return condition when ! thank very much


so, after adding nz, think problem of null solved

           service = nz(dlookup("intituleserv", "dbo_service", "idservice = " & dlookup("idservice", "dbo_professionnel", "idprofessionnel = " & dlookup("idcompte", "dbo_authentification", "login='" & me.txtlogin.value & "'"))), "inconnu")         forms![listingpatients]![txtintituleserv] = service 

but still have issue sql query, think didn't put correct syntax of sql query integrating in vba code, can take line :

        strsql = "select dbo_patient.*, dbo_service.intituleserv, dbo_hospitalisatacuelle.lit, dbo_professionnel.idprofessionnel, dbo_hospitalisatacuelle.dateentree, dbo_hospitalisatacuelle.datesortie dbo_service inner join ((dbo_professionnel inner join dbo_authentification on dbo_professionnel.idprofessionnel = dbo_authentification.idcompte) inner join (dbo_patient inner join (dbo_hospitalisatacuelle inner join dbo_donneepatientactuelles on dbo_hospitalisatacuelle.idhosp = dbo_donneepatientactuelles.idhosp) on dbo_patient.idpatient = dbo_donneepatientactuelles.idpatient) on dbo_professionnel.idprofessionnel = dbo_hospitalisatacuelle.idprofessionnel) on dbo_service.idservice = dbo_professionnel.idservice (((dbo_hospitalisatacuelle.dateentree)<=now()) , ((dbo_hospitalisatacuelle.datesortie)>now())) or (((dbo_hospitalisatacuelle.datesortie) null)) ;"         strsql = strsql & "where [dbo_service]![intituleserv] = ' " & service & " ' " docmd.openquery(strsql)  

thank you,

you have declared service string variable. dlookup returns null if no matching record found. null cannot stored in string, can stored in variant.

so either use dim service variant , test isnull()

or use service = nz(dlookup(...), "inconnu") return "inconnu" if dlookup() fails.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -