简体   繁体   中英

Teleform VBA recieving error remove preceding zeros then fill blank fields with one zero 20170412

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM