Reputation: 1
This is my VBA in a form for a program called Teleform. My tech support is only for the program and they are unable to assist with scripting to remove preceding zeros from collected data of 2 specific fields. The fields are numeric Month and day fields that are stored as text.
I need another script that will put a zero in all empty or blank data fields.
We found a script online that I have tried to accommodate to the preceding zero deletion. It runs but I receive the error "A runtime error occurred in the 'Form_Export' event of the 'Form_Script' project. Unspecified error (v11.0 11038)".
I am way over my head and in need of ur knowledge.
TIA for ur assistance! and Happy Happy Easter everyone!
Private Sub Form_Evaluate()
Sub Form_Export()
Function RemoveLeadingZeroes(ByVal MONTH) THIS PORTION SAMES IN RED TEXT, IF TRIED REMOVING BUT IT AND RECEIVE SAME ERROR MESSAGE.
Dim tempmonth
tempmonth = MONTH
While Left(tempmonth, 1) = "0" And tempmonth <> ""
tempmonth = Right(tempmonth, Len(tempmonth) - 1)
Wend
RemoveLeadingZeroes = tempmonth
End Sub
Function RemoveLeadingZeroes(ByVal DAY) THIS PORTION SAMES IN RED TEXT, IF TRIED REMOVING BUT IT AND RECEIVE SAME ERROR MESSAGE.
Dim tempday
tempday = DAY
While Left(tempday, 1) = "0" And tempday <> ""
tempday = Right(tempday, Len(tempday) - 1)
Wend
RemoveLeadingZeroes = tempday
Upvotes: 0
Views: 119
Reputation: 11755
Your function definitions are nested within a subroutine (actually 2) and that's not how it works... here, I will clean it up for you, but I did not test it to see if it does what you want, as integers do not have leading zeros.
Function RemoveLeadingZeroes(ByVal MONTH As String) As Integer
Dim tempmonth
tempmonth = MONTH
While Left(tempmonth, 1) = "0" And tempmonth <> ""
tempmonth = Right(tempmonth, Len(tempmonth) - 1)
Wend
RemoveLeadingZeroes = tempmonth
End Function
Function RemoveLeadingZeroes(ByVal DAY As String) As Integer
Dim tempday
tempday = DAY
While Left(tempday, 1) = "0" And tempday <> ""
tempday = Right(tempday, Len(tempday) - 1)
Wend
RemoveLeadingZeroes = tempday
End Function
Alternatively, you could just use the val()
function to turn a string into an integer.
Upvotes: 0