Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 On May 7, 4:02 pm, burl_rfc wrote: 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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 "burl_rfc" wrote: 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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On May 7, 4:28 pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote: 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 "burl_rfc" wrote: 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- Hide quoted text - - 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Run Time Error "13" Type Mismatch | Excel Programming | |||
Reasons for "Run-time error '13':Type mismatch"? | Excel Programming | |||
Error Handling to mitigate "Run Time Erorr 13 Type Mismatch" | Excel Programming | |||
Run-time Error "13" - File Type Mismatch | Excel Programming | |||
Help with Run-time error: "Type Mismatch" | Excel Programming |