View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
burl_rfc burl_rfc is offline
external usenet poster
 
Posts: 24
Default run time error 13 "type mis-match"

The code below adds the next seqential number to a text box on a form.

Everything works fine until I get to the following line, after
execution of the line of code I get the "type mis-match error":-
NextSeqNumber = "MIR-" & strNum

If I remove the "MIR-" & and simple use the following, it works fine
NextSeqNumber = strNum

I checked the user form to make sure that the text box is actually a
text box and it is.

Anyone have an idea what's causing the error.

Thanks
burl_rfc

Private Sub Userform_Initialize()

frmIncidentReport.txtIncidentNo.Value = NextSeqNumber

End Sub

Public Function NextSeqNumber(Optional sFileName As String, Optional
nSeqNumber = -1) As Long
Const sDefault_Path As String = "c:\documents and settings\my
documents"
Const sDefault_fName As String = "defaultseq.txt"
Dim nFileNumber As Long

nFileNumber = FreeFile
If sFileName = "" Then sFileName = sDefault_fName
If InStr(sFileName, Application.PathSeparator) = 0 Then _
sFileName = sDefault_Path & Application.PathSeparator &
sFileName
If nSeqNumber = -1& Then
If Dir(sFileName) < "" Then
Open sFileName For Input As nFileNumber
Input #nFileNumber, nSeqNumber
nSeqNumber = nSeqNumber + 1&
Close nFileNumber
Else
nSeqNumber = 1&
End If
End If
On Error GoTo PathError
Open sFileName For Output As nFileNumber
On Error GoTo 0
Print #nFileNumber, nSeqNumber
num = nSeqNumber
If num < 10 Then
strNum = "000" & CStr(num)
ElseIf num < 100 Then
strNum = "00" & CStr(num)
ElseIf num < 1000 And num 99 Then
strNum = "0" & CStr(num)
End If

Close nFileNumber
NextSeqNumber = "MIR-" & strNum
Exit Function

PathError:
NextSeqNumber = -1&

End Function