PDA

Click to See Complete Forum and Search --> : Access -- Using input mask as delimiter


kfcSmitty
Oct 24th, 2005, 09:16 AM
I am using an input mask to display my information as "99/99".

When I display the contents of the textbox it appears as "1003" instead of "10/03". It also saves it this way to the database. I am trying to use the split function to break it up into 2 seperate numbers IE 10 and 03 so I can save it into the database as "10/03".

The user can also enter the values as 10/3 or 1/1 or any variation, so I cannot simply split it per 2 digits.


Does anyone know how to either save a textbox to a database including the mask, or does anyone know how to split the textbox contents by the delimiter?


Thanks,
kfcSmitty

DKenny
Oct 24th, 2005, 10:33 AM
The following code will split the value in your testbox based on the position of the forward slash.


Private Sub Text8_AfterUpdate()
Dim MasterString As String
Dim SubString1 As String
Dim SubString2 As String

MasterString = Me.Text8

'First check if the field has a forward slash
If InStr(1, MasterString, "/") = 0 Then
Me.Text8 = ""
Exit Sub
End If

'Then Set the two substrings to the values to the left and right of the forward slash
SubString1 = Left(MasterString, InStr(1, MasterString, "/") - 1)
SubString2 = Mid(MasterString, InStr(1, MasterString, "/") + 1)

'Just to prove that it works
'replace this with your code
MsgBox SubString1
MsgBox SubString2
End Sub

dannymking
Oct 24th, 2005, 10:57 AM
You could also use the split function to populate the data into an array..


Dim Values() As String
If Instr(textbox1,"/") > 0 Then
Values = Split(textbox1,"/")
Msgbox Values(0)
Msgbox Values(1)
End If


However, you may be better off placing the imput mask on the text box and the relevant field in the table below to

00/00

This will force data entry in the format of two digits followed by "/" and then two digits, if this is not entered then the user will receive a message to this affect