สร้าง Module ขึ้นมาแล้วเอาฟังก์ชั่นนี้ไปใส่
Public Function FormatLocation(stLocation As String, zone_or_id As Byte) As String
Dim splitText() As String, nPart As Integer, stResult As String
splitText = Split(stLocation, "-")
nPart = UBound(splitText)
stResult = ""
If zone_or_id = 1 Then
stResult = splitText(0)
Else
If nPart > 0 Then
For i = 1 To nPart
stResult = stResult & Format(splitText(i), "000")
Next i
Else
stResult = "00000000"
End If
End If
FormatLocation = stResult
End Function
เสร็จแล้วก็สามารถใช้ Query แบบนี้ได้
SELECT Location, FormatLocation([Location],1) AS Zone, FormatLocation([Location],2) AS ID FROM tblName;