1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| Private Sub btnRemplirTable_Click()
Dim db As DAO.Database: Set db = CurrentDb
Dim rst As DAO.Recordset
Dim strSQL As String, strNomClient As String, strHotel As String, strVol As String
strHotel = ""
strVol = ""
'Récupérer le nom et le prénom
strSQL = "SELECT Clients.Nom, Clients.Prenom FROM Voyages INNER JOIN (Clients INNER JOIN Inscriptions ON Clients.RefClt = Inscriptions.RefClt) ON Voyages.RefVoyage = Inscriptions.RefPack " _
& "WHERE (((Clients.RefClt)=" & Me.RefClient & ") AND ((Voyages.RefVoyage)=" & Me.RefVoyage & "));"
Set rst = db.OpenRecordset(strSQL)
If rst.EOF = False Then
strNomClient = rst("Nom") & " " & rst("Prenom")
Else
'Ici tu pourrais mettre un message d'erreur disant que le client n'est pas trouvé
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Sub
End If
rst.Close
Set rst = Nothing
'Récupérer les hotels et concaténer
strSQL = "SELECT Hebergement.Hotel FROM Hebergement WHERE (((Hebergement.RefVoyage)=" & Me.RefVoyage & "));"
Set rst = db.OpenRecordset(strSQL)
While rst.EOF = False
If strHotel = "" Then
strHotel = rst("Hotel")
Else
strHotel = strHotel & ", " & rst("Hotel")
End If
rst.MoveNext
Wend
rst.Close
Set rst = Nothing
'Récupérer les vols et concaténer
strSQL = "SELECT Vols.noVol FROM Vols WHERE (((Vols.RefVoyage)=" & Me.RefVoyage & "));"
Set rst = db.OpenRecordset(strSQL)
While rst.EOF = False
If strVol = "" Then
strVol = rst("noVol")
Else
strVol = strVol & ", " & rst("noVol")
End If
rst.MoveNext
Wend
rst.Close
Set rst = Nothing
Set db = Nothing
'Ici on enregistre dans la table
strSQL = "INSERT INTO TaTable (RefVoyage, RefClient, NomVoyageur, Hotel, Vol) " _
& "VALUES (" & Me.RefVoyage & ", " & Me.RefClient & ", " & strNomClient & ", " & strHotel & ", " & strVol & ");)"
DoCmd.RunSQL strSQL
End Sub |
Partager