run time error 13 "type mis-match"

B

burl_rfc

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
 
M

Mark Lincoln

You're trying to return a string with 'NextSeqNumber = "MIR-" &
strNum', but your function starts out as:

Public Function NextSeqNumber(Optional sFileName As String, Optional
nSeqNumber = -1) As Long

I would guess the problem lies with the 'As Long'.

Mark Lincoln
 
M

merjet

Excel doesn't allow "-" in an object name. If you put a TextBox on a
UserForm manually and try to change the name to include a dash, it
responds with "not a legal object name."

Hth,
Merjet
 
G

Guest

Your function NextSeqNumber returns a long.

Public Function NextSeqNumber(Optional sFileName As String, Optional
nSeqNumber = -1) As Long

You can not assign a string to it as a return value. You could make the
retunr into a variant of a string if you wish...
 
B

burl_rfc

Your function NextSeqNumber returns a long.

Public Function NextSeqNumber(Optional sFileName As String, Optional
nSeqNumber = -1) As Long

You can not assign a string to it as a return value. You could make the
retunr into a variant of a string if you wish...
--
HTH...

Jim Thomlinson
















- Show quoted text -

Jim,

Thank you very miuch for the response, by changing the Public Fucition
callout from "Long' to "Variant", did the trick.

Thanks again.

burl_rfc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top