Access 数据库将文本排序到列中
Access Database sort text into columns
我有一个文本,例如:
fp(638,17:57,hh,ab).
fp(638,19:47,ms,an).
fp(638,19:49,ms,ab).
我想在 Access 列中对括号中的每个部分进行排序,以逗号分隔。
有没有简单的方法可以做到这一点。
结果应该看起来像这个问题的固定图像。
感谢您的努力。
假设数据已经是Access中的一个table中的一列,您可以使用几个字符串操作函数将数据拆分到不同的table中的列中。类似于:
Sub sSplitData()
On Error GoTo E_Handle
Dim db As DAO.Database
Dim rsIn As DAO.Recordset
Dim rsOut As DAO.Recordset
Dim strData As String
Dim astrData() As String
Set db = CurrentDb
Set rsIn = db.OpenRecordset("SELECT DataIn FROM tblDataIn;")
If Not (rsIn.BOF And rsIn.EOF) Then
Set rsOut = db.OpenRecordset("SELECT * FROM tblDataOut WHERE 1=2;") ' open a recordset that has no records selected for speed
Do
strData = rsIn!DataIn
strData = Mid(strData, 4) ' get rid of the "fp(" at the start
strData = Left(strData, Len(strData) - 2) ' get rid of the ")." at the end
astrData = Split(strData, ",") ' split the data based on commas
With rsOut
.AddNew
![Zug Nr] = astrData(0)
!Zeit = astrData(1)
!Stadt = astrData(2)
![AB/AN] = astrData(3)
.Update
End With
rsIn.MoveNext
Loop Until rsIn.EOF
End If
sExit:
On Error Resume Next
rsIn.Close
rsOut.Close
Set rsIn = Nothing
Set rsOut = Nothing
Set db = Nothing
Exit Sub
E_Handle:
MsgBox Err.Description & vbCrLf & vbCrLf & "sSplitData", vbOKOnly + vbCritical, "Error: " & Err.Number
Resume sExit
End Sub
此致,
我有一个文本,例如:
fp(638,17:57,hh,ab).
fp(638,19:47,ms,an).
fp(638,19:49,ms,ab).
我想在 Access 列中对括号中的每个部分进行排序,以逗号分隔。 有没有简单的方法可以做到这一点。 结果应该看起来像这个问题的固定图像。
感谢您的努力。
假设数据已经是Access中的一个table中的一列,您可以使用几个字符串操作函数将数据拆分到不同的table中的列中。类似于:
Sub sSplitData()
On Error GoTo E_Handle
Dim db As DAO.Database
Dim rsIn As DAO.Recordset
Dim rsOut As DAO.Recordset
Dim strData As String
Dim astrData() As String
Set db = CurrentDb
Set rsIn = db.OpenRecordset("SELECT DataIn FROM tblDataIn;")
If Not (rsIn.BOF And rsIn.EOF) Then
Set rsOut = db.OpenRecordset("SELECT * FROM tblDataOut WHERE 1=2;") ' open a recordset that has no records selected for speed
Do
strData = rsIn!DataIn
strData = Mid(strData, 4) ' get rid of the "fp(" at the start
strData = Left(strData, Len(strData) - 2) ' get rid of the ")." at the end
astrData = Split(strData, ",") ' split the data based on commas
With rsOut
.AddNew
![Zug Nr] = astrData(0)
!Zeit = astrData(1)
!Stadt = astrData(2)
![AB/AN] = astrData(3)
.Update
End With
rsIn.MoveNext
Loop Until rsIn.EOF
End If
sExit:
On Error Resume Next
rsIn.Close
rsOut.Close
Set rsIn = Nothing
Set rsOut = Nothing
Set db = Nothing
Exit Sub
E_Handle:
MsgBox Err.Description & vbCrLf & vbCrLf & "sSplitData", vbOKOnly + vbCritical, "Error: " & Err.Number
Resume sExit
End Sub
此致,