Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Access > VBA Access
VBA Access Le forum pour les questions relatives au code VBA sous Access, et à son environnement de développement VBE.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 08/10/2011, 02h57   #1
Membre actif
 
Avatar de robyseb
 
Homme Sébastien
Développeur indépendant
Inscription : juillet 2011
Messages : 178
Détails du profil
Informations personnelles :
Nom : Homme Sébastien
Localisation : Canada

Informations professionnelles :
Activité : Développeur indépendant

Informations forums :
Inscription : juillet 2011
Messages : 178
Points : 193
Points : 193
Par défaut Ouverture Formulaire selon 2 critères plantage access

Bonjour ! Voici un bout de code que j'ai écrit afin de pouvoir ouvrir un formulaire selon 2 critères soit Prenom et nom j'ai tenté plusieurs approche mais il n'y a pas grand chose qui fonctionne et même que ma dernière tentative crash access .... En rajoutant (DBopenDynaset) poufff access ne répond plus.
Biensur si vous avez des idées pour changer ma méthode elle est la bienvenue merci de m'aidez à résoudre un autre problématique les amis.

voici le code placé sur le formulaire qui contient les critères :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
Private Sub choixpatient_AfterUpdate()
Dim choixpatient1 As String
Dim choixpatient2 As String
choixpatient1 = Me.choixpatient.Column(1)
choixpatient2 = Me.choixpatient.Column(2)
DoCmd.Close
DoCmd.OpenForm "rapportintervention", acNormal, , , , , "" & choixpatient1 & " ; " & choixpatient2 & ""
logEntrylIVE ("Ouverture du Rapport d'intervention de " & choixpatient1 & " " & choixpatient2 & "")
 
choixpatient1 = ""
choixpatient2 = ""
End Sub


Voici le code placé sur le formload du formulaire Rapport d'intervention .

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Dim identitePatient As Variant
Dim PrenomPatientArg As String
Dim NomPatientArg As String
 
identitePatient = Split(Me.OpenArgs, ";")
 
prenompatientArg =  identitePatient(0)
nompatientArg =  identitePatient(1)
 
 
Dim MaTable As dao.Recordset
Dim db As dao.Database
Set MaTable = CurrentDb.OpenRecordset("tbl_rapportintervention", dbOpenDynaset)'ici j'ai le plantage si je l'enlève j'ai une erreur 3251 "opération non autorisé pour se type d'objet"
Do Until MaTable.EOF = True
        MaTable.FindFirst "[Nompatient] = '" & NomPatientArg & "' AND [Prenompatient] = '" & PrenomPatientArg & "'" 'qui me souligne cette ligne 
 
 
MaTable.MoveNext
Loop
MaTable.Close
 
 
End If
robyseb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/10/2011, 08h32   #2
Membre Expert
 
Inscription : août 2006
Messages : 1 435
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 1 435
Points : 1 753
Points : 1 753
Bonjour,
Et sans préciser ?
Code :
1
2
 
Set MaTable = CurrentDb.OpenRecordset("tbl_rapportintervention")
helas est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/10/2011, 15h07   #3
Membre actif
 
Avatar de robyseb
 
Homme Sébastien
Développeur indépendant
Inscription : juillet 2011
Messages : 178
Détails du profil
Informations personnelles :
Nom : Homme Sébastien
Localisation : Canada

Informations professionnelles :
Activité : Développeur indépendant

Informations forums :
Inscription : juillet 2011
Messages : 178
Points : 193
Points : 193
Salut merci de m'aider

si je l'enlève j'ai une erreur 3251 "opération non autorisé pour se type d'objet"
et l'éditeur souligne cette ligne
Code :
MaTable.FindFirst "[Nompatient] = '" & NomPatientArg & "' AND [Prenompatient] = '" & PrenomPatientArg & "'"
je me demandais si ceci pourrait fonctionner
Code :
DoCmd.FindRecord "nompatient=' & NomPatientArg & '" And "prenompatient=' & PrenomPatientArg & '", acAnywhere, False, , True, acAll
robyseb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/10/2011, 15h41   #4
Membre Expert
 
Inscription : août 2006
Messages : 1 435
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 1 435
Points : 1 753
Points : 1 753
Après avoir testé
Code :
1
2
 
Set MaTable = CurrentDb.OpenRecordset("tbl_rapportintervention", dbOpenSnapshot)
ne retourne pas d'erreur
helas est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/10/2011, 15h57   #5
Membre actif
 
Avatar de robyseb
 
Homme Sébastien
Développeur indépendant
Inscription : juillet 2011
Messages : 178
Détails du profil
Informations personnelles :
Nom : Homme Sébastien
Localisation : Canada

Informations professionnelles :
Activité : Développeur indépendant

Informations forums :
Inscription : juillet 2011
Messages : 178
Points : 193
Points : 193
salut je ne comprend pas moi access cesse de répondre et crash ...
robyseb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/10/2011, 16h21   #6
Membre actif
 
Avatar de robyseb
 
Homme Sébastien
Développeur indépendant
Inscription : juillet 2011
Messages : 178
Détails du profil
Informations personnelles :
Nom : Homme Sébastien
Localisation : Canada

Informations professionnelles :
Activité : Développeur indépendant

Informations forums :
Inscription : juillet 2011
Messages : 178
Points : 193
Points : 193
Je vais tenter d'expliquer ce que je désire faire !

1- j'ai un formulaire "choixrapport" qui possède une liste déroulante avec 3 colones qui affiche le prénom et nom d'un patient donc sur le "afterupdate" de la liste j'ai écrit ce code :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
Private Sub choixpatient_AfterUpdate()
Dim choixpatient1 As String
Dim choixpatient2 As String
choixpatient1 = Me.choixpatient.Column(1)
choixpatient2 = Me.choixpatient.Column(2)
DoCmd.Close
DoCmd.OpenForm "rapportintervention", acNormal, , , , , "" & choixpatient1 & " ; " & choixpatient2 & ""
 
 
choixpatient1 = ""
choixpatient2 = ""
End Sub
Ensuite lors de l'ouverture du formulaire je veut trouver le premier record qui match les 2 variables soit "choixpatient1" et "choixpatient2" donc j'ai écrit au formload du formulaire ce code mais ca ne fonctionne toujour pas même avec tes indications HELAS est-ce que vous pensées à une autre méthode qui pourrait fonctionner
robyseb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/10/2011, 19h37   #7
Membre actif
 
Avatar de robyseb
 
Homme Sébastien
Développeur indépendant
Inscription : juillet 2011
Messages : 178
Détails du profil
Informations personnelles :
Nom : Homme Sébastien
Localisation : Canada

Informations professionnelles :
Activité : Développeur indépendant

Informations forums :
Inscription : juillet 2011
Messages : 178
Points : 193
Points : 193
Bonjour à tous j'ai résolu mon problème .... je vous explique j'ai rajouté un champ dans ma table qui contient maintenant le prenom et nom regroupé qui s'enregistre lors de la sauvegarde du formulaire! Je devait m'y prendre de cette manière puisque si j'avait 2 pierre par exemple ca aurai causé problème et je doit continuer d'utiliser un champ séparé pour le Prénom et le nom

Sous mon code du premier formulaire ChoixPatient :
Code :
1
2
3
4
5
6
7
8
9
10
Private Sub choixpatient_AfterUpdate()
Dim choixpatient1 As String
Dim choixpatient2 As String
Dim choixpatient As String
choixpatient1 = Me.choixpatient.Column(1)
choixpatient2 = Me.choixpatient.Column(2)
choixpatient = "" & choixpatient1 & "" & choixpatient2 & ""
 
DoCmd.Close
DoCmd.OpenForm "rapportintervention", acNormal, , , , , "" & choixpatient & ""
j'ai créer une variable qui regroupe le prenom et le nom !

Ensuite lors du FormLoad du rapport :
Code :
1
2
3
4
5
6
7
Dim identitePatient As Variant
 
    identitePatient = Me.OpenArgs
    Me.Nomcomplet.Visible = True
   DoCmd.FindRecord identitePatient, acAnywhere, False, , True
    Me.PrenomPatient.SetFocus
    Me.Nomcomplet.Visible = False
je recherche la nouvelle case qui contient le prenom et nom regroupé et voila !!

En espérant que ca puisse aider quelqu'un d'autre merci
robyseb est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 19h37.


 
 
 
 
Partenaires

Hébergement Web