Conversion on Text into number (with 2 decimal) - using MS Access 2003

  • Dear all Gurus/Masters

    I am importing text file into MS access 2003 table

    text file data is as follows

    emp code intime outtime

    E2900 0.00 0.00

    E2901 7.30 15.35

    E2902 7.32 15.37

    Now, my problem is how to convert intime and outtime from above

    data into ms access table

    I am using following code. Pls note that I am trying VAL() function but not working properly.

    Private Sub new_imp_Click()

    On Error GoTo E_Handle

    Dim db As Database

    'Dim rsCD As Recordset, rsTrack As Recordset

    ', rsBand As Recordset

    Dim rsATT As Recordset

    Dim strFile As String, strText As String, strCriteria As String

    Dim myemp As String

    Dim blnNewRecord As Boolean

    Set db = DBEngine(0)(0)

    Set rsATT = db.OpenRecordset("Swipes", dbOpenDynaset)

    strFile = "C:\Swipes.txt" ' The normal location of the file

    Open strFile For Input As #1

    Do While Not EOF(1)

    Line Input #1, strText

    MsgBox (strText)

    myemp = Mid(strText, 1, 5)

    With rsATT

    .AddNew

    !EMPCODE = Mid(strText, 1, 5)

    !intime = Val(Mid(strText, 31, 5))

    !outtime = Val(Mid(strText, 36, 5))

    .Update

    End With

    Loop

    sExit:

    On Error Resume Next

    Close #1

    rsCD.Close

    rsBand.Close

    rsTrack.Close

    Set rsCD = Nothing

    Set rsBand = Nothing

    Set rsTrack = Nothing

    Set db = Nothing

    Exit Sub

    E_Handle:

    MsgBox Err.DESCRIPTION, vbOKOnly + vbCritical, "Error: " & Err.Number

    Resume sExit

    End Sub

    Anticipating your guidence.

    tks and b rgds

    sunil joshi

  • Replace your VAL function by CSNG, then use FORMAT function.

    May it help.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply