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 56 57 58 59 60
|
Private Sub Commande110_Click()
fnFieldSplit "Point", "coordinates", "x", "y", "z", ","
End Sub
Function fnFieldSplit(sTable As String, _
sFieldToSplit As String, _
sNewField1 As String, _
sNewField2 As String, _
sNewField3 As String, _
sSeparator As String)
Dim DB As DAO.Database
Dim RS As DAO.Recordset
Dim sC1 As String, sC2 As String, sC3 As String
Dim Pos As Long
Dim Pos2 As Long
Set DB = CurrentDb
'Set sTable = Point
'Set sFieldToSplit = coordinates
'Set sNewField1 = x
'Set sNewField2 = y
'Set sSeparator = ","
'ajout des trois champs
CurrentDb.Execute "ALTER TABLE [" & sTable & "] " _
& "ADD COLUMN [" & sNewField1 & "] TEXT;"
CurrentDb.Execute "ALTER TABLE [" & sTable & "] " _
& "ADD COLUMN [" & sNewField2 & "] TEXT;"
'CurrentDb.Execute "ALTER TABLE [" & sTable & "] "
'& "ADD COLUMN [" & sNewField3 & "] TEXT;"
Set RS = DB.OpenRecordset(sTable)
'boucle sur les enregistrements
Do Until RS.EOF
Pos = InStr(RS(sFieldToSplit), sSeparator)
sC1 = Trim(Left(RS(sFieldToSplit), Pos - 1))
sC2 = Trim(Mid(RS(sFieldToSplit), Pos + 1))
'sC3 = Trim(Right(RS(sFieldToSplit), Pos + 1))
RS.Edit
RS(sNewField1) = sC1
RS(sNewField2) = sC2
RS.Update
RS.MoveNext
Loop
'libérer
RS.Close
DB.Close
Set RS = Nothing
Set DB = Nothing
MsgBox "vorgang abgeschlossen"
Exit Function
End Function |
Partager