I want to open a form in add mode and when a user enters a client contract number that already exists, the user gets noticed by a msgbox and then the record with this particular client number becomes the current record shown in the form.
I have all the code to validate the client contract number but it's how to show the record in the form I'm having trouble with.
I've tried DoCmd.FindRecord but I get an Access error message saying that I used a macro in an inapropriate way. I don't use macro for this.
I've tried to close and then open the form with an SQL statement or an openargs but I get an Access error message saying that a "cancel" was called upon the OpenForm method.
I've tried opening the form in edit mode, same result.
I just don't see what i'm doing wrong. I sounds simple. The code is pretty straight forward.
I'm calling this code from a button but I'll want to get rid of the button and automate this. It's in design state so forgive me if it's a little bit rough around the edges!
Option Compare Database
Option Explicit
Private Sub rechNoClient_Click()
On Error GoTo Err_rechNoClient_Click
Dim db As Database 'cause I have
Dim recDétails As Recordset
Dim recClient As Recordset
Dim clientTrouvé As Boolean
Set db = CurrentDb()
Set recDétails = db.OpenRecordset("TAppelDétails", dbOpenTable)
Set recClient = db.OpenRecordset("TClients", dbOpenTable)
clientTrouvé = False
If Me!NoContrat1 = "" Then
MsgBox "Vous devez spécifier un numéro de contrat avant de lancer une recherche!", _
vbCritical, "Recherche sans numéro de contrat"
Exit Sub
End If
recClient.Index = "NoContrat1"
recClient.Seek "=", Me!NoContrat1
If recClient.NoMatch = True Then
recClient.Index = "NoContrat2"
recClient.Seek "=", Me!NoContrat1
If recClient.NoMatch = True Then
recClient.Index = "NoContrat3"
recClient.Seek "=", Me!NoContrat1
If recClient.NoMatch = False Then
clientTrouvé = True
End If
Else
clientTrouvé = True
End If
Else
clientTrouvé = True
End If
If clientTrouvé = True Then
NoClientARechercher = Me!NoContrat1
DoCmd.FindRecord NoClientARechercher
Else
MsgBox "Aucun enregistrement pour ce numéro de contrat. Saisir la nouvelle entrée ou modifier le numéro de contrat saisi et recommencer la recherche", _
vbInformation, "Recherche infructueuse!"
End If
recClient.Close
recDétails.Close
Exit_rechNoClient_Click:
Exit Sub
Err_rechNoClient_Click:
MsgBox Err.Description
Resume Exit_rechNoClient_Click
End Sub
Thanks
I have all the code to validate the client contract number but it's how to show the record in the form I'm having trouble with.
I've tried DoCmd.FindRecord but I get an Access error message saying that I used a macro in an inapropriate way. I don't use macro for this.
I've tried to close and then open the form with an SQL statement or an openargs but I get an Access error message saying that a "cancel" was called upon the OpenForm method.
I've tried opening the form in edit mode, same result.
I just don't see what i'm doing wrong. I sounds simple. The code is pretty straight forward.
I'm calling this code from a button but I'll want to get rid of the button and automate this. It's in design state so forgive me if it's a little bit rough around the edges!
Option Compare Database
Option Explicit
Private Sub rechNoClient_Click()
On Error GoTo Err_rechNoClient_Click
Dim db As Database 'cause I have
Dim recDétails As Recordset
Dim recClient As Recordset
Dim clientTrouvé As Boolean
Set db = CurrentDb()
Set recDétails = db.OpenRecordset("TAppelDétails", dbOpenTable)
Set recClient = db.OpenRecordset("TClients", dbOpenTable)
clientTrouvé = False
If Me!NoContrat1 = "" Then
MsgBox "Vous devez spécifier un numéro de contrat avant de lancer une recherche!", _
vbCritical, "Recherche sans numéro de contrat"
Exit Sub
End If
recClient.Index = "NoContrat1"
recClient.Seek "=", Me!NoContrat1
If recClient.NoMatch = True Then
recClient.Index = "NoContrat2"
recClient.Seek "=", Me!NoContrat1
If recClient.NoMatch = True Then
recClient.Index = "NoContrat3"
recClient.Seek "=", Me!NoContrat1
If recClient.NoMatch = False Then
clientTrouvé = True
End If
Else
clientTrouvé = True
End If
Else
clientTrouvé = True
End If
If clientTrouvé = True Then
NoClientARechercher = Me!NoContrat1
DoCmd.FindRecord NoClientARechercher
Else
MsgBox "Aucun enregistrement pour ce numéro de contrat. Saisir la nouvelle entrée ou modifier le numéro de contrat saisi et recommencer la recherche", _
vbInformation, "Recherche infructueuse!"
End If
recClient.Close
recDétails.Close
Exit_rechNoClient_Click:
Exit Sub
Err_rechNoClient_Click:
MsgBox Err.Description
Resume Exit_rechNoClient_Click
End Sub
Thanks