Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Modifier une table, requete, form, etc

2 réponses
Avatar
Albus
Bonjour
Comment est il possible de faire modifier automatiquement une composante
d'access ?
Je m'explique :
J'ai donné à M. machin la base de données X
Je me rends compte que dans la table 1, j'ai oublié un champ.
Comment lui faire une mise à jour juste de la table et de ses liens sans
qu'il ait besoin de ressaisir toutes les données ???
Suis je clair ??

Merci

2 réponses

Avatar
Fred
Bjr,

Si tu dois ajouter un champ dans une table liée, je te conseille cette
fonction:

'Exemple :
'AjoutChampDansTable("SuiviCourrier","Traite",dbboolean,false,"C:BaseDeDonnees.mdb
")

Function AjoutChampDansTable(table As String, Champ As String, TypeChamp As
Integer, NumAuto As Boolean, Optional NomBase As String, Optional ValDefT As
String, Optional FormatChamp As Integer, Optional LibelleChamp As String) As
Long
'Nombase chemin complet de la base
On Error GoTo AjoutChampDansTable_Error

Dim bds As Database, CheminBase As String
Dim tdf As TableDef, fld As Field, chp As Field
Dim wrkJet As Workspace

If IsNull(NomBase) Or IsEmpty(NomBase) Or NomBase = "" Then
CheminBase = CurrentDb.Name
Else
CheminBase = NomBase
End If

Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
Set bds = wrkJet.OpenDatabase(CheminBase)

' Crée un nouvel objet TableDef.
Set tdf = bds.TableDefs(table)

'Creation du champ
Set fld = tdf.CreateField(Champ, TypeChamp)
'Creation du champ auto
If NumAuto And TypeChamp = dbLong Then
fld.OrdinalPosition = 1
fld.Attributes = dbAutoIncrField
End If
'Valeur par defaut texte
If IsNull(ValDefT) Or IsEmpty(ValDefT) Or ValDefT = "" Then
Else
fld.DefaultValue = ValDefT
End If

'activation du champ
tdf.Fields.Append fld

'Libelle Champ
If IsNull(LibelleChamp) Or IsEmpty(LibelleChamp) Or LibelleChamp = ""
Then
Else
Set chp = tdf.Fields(Champ)
Call DéfinirPropriété(chp, "Description", dbText, LibelleChamp)
End If

'Definition du format de champ
If FormatChamp > 0 Then
GoSub FormatDeChamp
End If


Fin:

bds.Close
wrkJet.Close
Set fld = Nothing
Set bds = Nothing
Set chp = Nothing
Set tdf = Nothing
Set wrkJet = Nothing

Exit Function

AjoutChampDansTable_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
AjoutChampDansTable of Module Ajout Champ dans Table"
Resume Fin
'=============================================================================== ' Création de propriétés pour certains champs
'utilise la fonction DéfinirPropriété du module DéfinirPropriétéAccess
'=============================================================================== FormatDeChamp:
Select Case FormatChamp
Case 1
'----------------------------------
'Case a cocher *
'----------------------------------
Set chp = tdf.Fields(Champ) 'acCheckBox = Case à cocher (106)
'Propriété DisplayControl
Call DéfinirPropriété(chp, "DisplayControl", dbInteger, acCheckBox)
Call DéfinirPropriété(chp, "Format", dbText, "True/False")

Case 3
'----------------------------------
'Zone de texte *
'----------------------------------
Set chp = tdf.Fields(Champ) 'acTextBox = Zone de texte
Call DéfinirPropriété(chp, "DisplayControl", dbInteger, acTextBox)

Case 3
'----------------------------------
'Zone de liste *
'----------------------------------
Set chp = tdf.Fields(Champ) 'acListBox = Zone de liste
Call DéfinirPropriété(chp, "DisplayControl", dbInteger, acListBox)

Case 4
'----------------------------------
'Zone de liste Modifiable *
'----------------------------------
Set chp = tdf.Fields(Champ) 'acComboBox = Zone de liste modifiable
Call DéfinirPropriété(chp, "DisplayControl", dbInteger, acComboBox)
Call DéfinirPropriété(chp, "RowSourceType", dbText, "Table/requête")
'"Table/requête", "Liste valeurs" ou "Liste champs"
Call DéfinirPropriété(chp, "RowSource", dbText, "CourrierNumerise")
Call DéfinirPropriété(chp, "ColumnCount ", dbText, "4")
'Call DéfinirPropriété(chp, "ColumnWidths", dbText, "")
Call DéfinirPropriété(chp, "ListWidth", dbText, "12")
Call DéfinirPropriété(chp, "LimitToList", dbBoolean, True)



End Select
Return


End Function
'=================================================== 'Call DéfinirPropriété(chp, "Format", dbText, "True/False") '"Yes/No" ou
'"True/False" ou "On/Off"


"Albus" a écrit dans le message de news:
4422d81a$0$20164$
Bonjour
Comment est il possible de faire modifier automatiquement une composante
d'access ?
Je m'explique :
J'ai donné à M. machin la base de données X
Je me rends compte que dans la table 1, j'ai oublié un champ.
Comment lui faire une mise à jour juste de la table et de ses liens sans
qu'il ait besoin de ressaisir toutes les données ???
Suis je clair ??

Merci



Avatar
Albus
Ouf !! merci pour tout !!!
J'essaie !
"Fred" a écrit dans le message de news:
44239d42$0$20169$
Bjr,

Si tu dois ajouter un champ dans une table liée, je te conseille cette
fonction:

'Exemple :
'AjoutChampDansTable("SuiviCourrier","Traite",dbboolean,false,"C:BaseDeDonnees.mdb
")

Function AjoutChampDansTable(table As String, Champ As String, TypeChamp
As Integer, NumAuto As Boolean, Optional NomBase As String, Optional
ValDefT As String, Optional FormatChamp As Integer, Optional LibelleChamp
As String) As Long
'Nombase chemin complet de la base
On Error GoTo AjoutChampDansTable_Error

Dim bds As Database, CheminBase As String
Dim tdf As TableDef, fld As Field, chp As Field
Dim wrkJet As Workspace

If IsNull(NomBase) Or IsEmpty(NomBase) Or NomBase = "" Then
CheminBase = CurrentDb.Name
Else
CheminBase = NomBase
End If

Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
Set bds = wrkJet.OpenDatabase(CheminBase)

' Crée un nouvel objet TableDef.
Set tdf = bds.TableDefs(table)

'Creation du champ
Set fld = tdf.CreateField(Champ, TypeChamp)
'Creation du champ auto
If NumAuto And TypeChamp = dbLong Then
fld.OrdinalPosition = 1
fld.Attributes = dbAutoIncrField
End If
'Valeur par defaut texte
If IsNull(ValDefT) Or IsEmpty(ValDefT) Or ValDefT = "" Then
Else
fld.DefaultValue = ValDefT
End If

'activation du champ
tdf.Fields.Append fld

'Libelle Champ
If IsNull(LibelleChamp) Or IsEmpty(LibelleChamp) Or LibelleChamp = ""
Then
Else
Set chp = tdf.Fields(Champ)
Call DéfinirPropriété(chp, "Description", dbText, LibelleChamp)
End If

'Definition du format de champ
If FormatChamp > 0 Then
GoSub FormatDeChamp
End If


Fin:

bds.Close
wrkJet.Close
Set fld = Nothing
Set bds = Nothing
Set chp = Nothing
Set tdf = Nothing
Set wrkJet = Nothing

Exit Function

AjoutChampDansTable_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
AjoutChampDansTable of Module Ajout Champ dans Table"
Resume Fin
'=============================================================================== > ' Création de propriétés pour certains champs
'utilise la fonction DéfinirPropriété du module DéfinirPropriétéAccess
'=============================================================================== > FormatDeChamp:
Select Case FormatChamp
Case 1
'----------------------------------
'Case a cocher *
'----------------------------------
Set chp = tdf.Fields(Champ) 'acCheckBox = Case à cocher (106)
'Propriété DisplayControl
Call DéfinirPropriété(chp, "DisplayControl", dbInteger, acCheckBox)
Call DéfinirPropriété(chp, "Format", dbText, "True/False")

Case 3
'----------------------------------
'Zone de texte *
'----------------------------------
Set chp = tdf.Fields(Champ) 'acTextBox = Zone de texte
Call DéfinirPropriété(chp, "DisplayControl", dbInteger, acTextBox)

Case 3
'----------------------------------
'Zone de liste *
'----------------------------------
Set chp = tdf.Fields(Champ) 'acListBox = Zone de liste
Call DéfinirPropriété(chp, "DisplayControl", dbInteger, acListBox)

Case 4
'----------------------------------
'Zone de liste Modifiable *
'----------------------------------
Set chp = tdf.Fields(Champ) 'acComboBox = Zone de liste modifiable
Call DéfinirPropriété(chp, "DisplayControl", dbInteger, acComboBox)
Call DéfinirPropriété(chp, "RowSourceType", dbText, "Table/requête")
'"Table/requête", "Liste valeurs" ou "Liste champs"
Call DéfinirPropriété(chp, "RowSource", dbText, "CourrierNumerise")
Call DéfinirPropriété(chp, "ColumnCount ", dbText, "4")
'Call DéfinirPropriété(chp, "ColumnWidths", dbText, "")
Call DéfinirPropriété(chp, "ListWidth", dbText, "12")
Call DéfinirPropriété(chp, "LimitToList", dbBoolean, True)



End Select
Return


End Function
'=================================================== > 'Call DéfinirPropriété(chp, "Format", dbText, "True/False") '"Yes/No" ou
'"True/False" ou "On/Off"


"Albus" a écrit dans le message de news:
4422d81a$0$20164$
Bonjour
Comment est il possible de faire modifier automatiquement une composante
d'access ?
Je m'explique :
J'ai donné à M. machin la base de données X
Je me rends compte que dans la table 1, j'ai oublié un champ.
Comment lui faire une mise à jour juste de la table et de ses liens sans
qu'il ait besoin de ressaisir toutes les données ???
Suis je clair ??

Merci