I have the following code I need help because it does not work.
Private Sub Command0_Click()
Dim NUMCHECK As Integer
Dim SURN As String
Dim CD As String
Dim CURCH As String
Dim PREVNO As String
Dim ADNUM As String
Dim PREVCH As String
Dim LONGA As Integer
Dim C1 As String
Dim C2 As String
Dim C3 As String
Dim C4 As String
Dim C5 As String
Dim C6 As String
Dim VOWEL As String
Dim WH As String
Dim dbSpecimen As Object
Dim rst As Object
Dim fldEnumerator As Object
Dim fldColumns As Object
'Set dbSpecimen = CurrentDb
'Set rst = dbSpecimen.OpenRecordset("HiCUP surv")
'Set fldColumns = rst.Fields
' Scan the records from beginning to each
VOWEL = "AEIOUY',."
WH = "WH '-"
C1 = "BFPV"
C2 = "CGJKQSXZ"
C3 = "DT"
C4 = "L"
C5 = "MN"
C6 = "R"
Set db = CurrentDb()
Set rst = db.OpenRecordset("TestPertussis")
'Useful code here.
While Not rst.EOF
For Each fldEnumerator In rst.Fields
rst.Edit
If Confirmation = "confirmed measles" And (IsNull(Soundex1) = True) And (IsNull(PATIENTNAM) = True) Then
Exit Sub
End If
If Confirmation = "confirmed measles" And (IsNull(Soundex1) = False) And (IsNull(PATIENTNAM) = True) Then
'message current item number
LONGA = Left(PATIENTNAM, 1)
MsgBox (LONGA)
NUMCHECK = 0
PR = 0
Do While NUMCHECK = 0 And PR < LONGA
PR = PR + 1
If InStr("1234567890", (Mid("PATIENTNAM", 1)), PR, 1) > 0 Then
NUMCHECK = 1
End If
If NUMCHECK = 0 Then
SURN = Left(Surname, 1)
LONGA = Len(PATIENTNAM)
If (Left(PATIENTNAM, 3) = "ST " Or Left(PATIENTNAM, 3) = "ST.") Then
SURN = ("SAINT" & Mid(PATIENTNAM, 4, LONGA - 3))
If Mid(SURN, 6, 1) = " " Then
SURN = ("SAINT" & Mid(PATIENTNAM, 5, LONGA - 4))
End If
SURN = Left(SURN, 1)
End If
LONGA = Len(SURN)
If LONGA <= 2 Then
SURN = Left(PATIENTNAM, 2)
LONGA = Len(SURN)
End If
PR = 0
CD = (Left(SURN, 1) & "-")
PREVNO = ""
CURCH = ""
Do While PR < LONGA And Len(CD) < 5 'DO
PR = PR + 1
ADNUM = ""
CURCH = Mid(SURN, PR, 1)
If InStr(WH, CURCH) = 0 Then
If InStr(VOWEL, CURCH) = 0 Then
If InStr(C1, CURCH) > 0 Then
ADNUM = "1"
Else
If InStr(C2, CURCH) > 0 Then
ADNUM = "2"
Else
If InStr(C3, CURCH) > 0 Then
ADNUM = "3"
Else
If InStr(C4, CURCH) > 0 Then
ADNUM = "4"
Else
If InStr(C5, CURCH) > 0 Then
ADNUM = "5"
Else
If InStr(C6, CURCH) > 0 Then
ADNUM = "6"
End If
End If
End If
End If
End If
End If
If ADNUM = PREVNO And PR > 1 Then
If PREVCH = "V" Then
CD = (CD & ADNUM)
End If
Else
If InStr("123456", ADNUM) > 0 And PR > 1 Then
CD = (CD & ADNUM)
End If
End If
PREVNO = ADNUM
Else
If InStr(C6, CURCH) > 0 Then
ADNUM = "6"
End If
End If
End If
'End If
'End If
'End If
If ADNUM = PREVNO And PR > 1 Then
If PREVCH = "V" Then
CD = (CD & ADNUM)
End If
Else
If InStr("123456", ADNUM) > 0 And PR > 1 Then
CD = (CD & ADNUM)
End If
End If
PREVNO = ADNUM
'End If
rst.Update
'Next
' Move to the next record and continue the same approach
rst.MoveNext
'Wend
Loop
End If
rst.Close
Set rst = Nothing
End Sub
Private Sub Command0_Click()
Dim NUMCHECK As Integer
Dim SURN As String
Dim CD As String
Dim CURCH As String
Dim PREVNO As String
Dim ADNUM As String
Dim PREVCH As String
Dim LONGA As Integer
Dim C1 As String
Dim C2 As String
Dim C3 As String
Dim C4 As String
Dim C5 As String
Dim C6 As String
Dim VOWEL As String
Dim WH As String
Dim dbSpecimen As Object
Dim rst As Object
Dim fldEnumerator As Object
Dim fldColumns As Object
'Set dbSpecimen = CurrentDb
'Set rst = dbSpecimen.OpenRecordset("HiCUP surv")
'Set fldColumns = rst.Fields
' Scan the records from beginning to each
VOWEL = "AEIOUY',."
WH = "WH '-"
C1 = "BFPV"
C2 = "CGJKQSXZ"
C3 = "DT"
C4 = "L"
C5 = "MN"
C6 = "R"
Set db = CurrentDb()
Set rst = db.OpenRecordset("TestPertussis")
'Useful code here.
While Not rst.EOF
For Each fldEnumerator In rst.Fields
rst.Edit
If Confirmation = "confirmed measles" And (IsNull(Soundex1) = True) And (IsNull(PATIENTNAM) = True) Then
Exit Sub
End If
If Confirmation = "confirmed measles" And (IsNull(Soundex1) = False) And (IsNull(PATIENTNAM) = True) Then
'message current item number
LONGA = Left(PATIENTNAM, 1)
MsgBox (LONGA)
NUMCHECK = 0
PR = 0
Do While NUMCHECK = 0 And PR < LONGA
PR = PR + 1
If InStr("1234567890", (Mid("PATIENTNAM", 1)), PR, 1) > 0 Then
NUMCHECK = 1
End If
If NUMCHECK = 0 Then
SURN = Left(Surname, 1)
LONGA = Len(PATIENTNAM)
If (Left(PATIENTNAM, 3) = "ST " Or Left(PATIENTNAM, 3) = "ST.") Then
SURN = ("SAINT" & Mid(PATIENTNAM, 4, LONGA - 3))
If Mid(SURN, 6, 1) = " " Then
SURN = ("SAINT" & Mid(PATIENTNAM, 5, LONGA - 4))
End If
SURN = Left(SURN, 1)
End If
LONGA = Len(SURN)
If LONGA <= 2 Then
SURN = Left(PATIENTNAM, 2)
LONGA = Len(SURN)
End If
PR = 0
CD = (Left(SURN, 1) & "-")
PREVNO = ""
CURCH = ""
Do While PR < LONGA And Len(CD) < 5 'DO
PR = PR + 1
ADNUM = ""
CURCH = Mid(SURN, PR, 1)
If InStr(WH, CURCH) = 0 Then
If InStr(VOWEL, CURCH) = 0 Then
If InStr(C1, CURCH) > 0 Then
ADNUM = "1"
Else
If InStr(C2, CURCH) > 0 Then
ADNUM = "2"
Else
If InStr(C3, CURCH) > 0 Then
ADNUM = "3"
Else
If InStr(C4, CURCH) > 0 Then
ADNUM = "4"
Else
If InStr(C5, CURCH) > 0 Then
ADNUM = "5"
Else
If InStr(C6, CURCH) > 0 Then
ADNUM = "6"
End If
End If
End If
End If
End If
End If
If ADNUM = PREVNO And PR > 1 Then
If PREVCH = "V" Then
CD = (CD & ADNUM)
End If
Else
If InStr("123456", ADNUM) > 0 And PR > 1 Then
CD = (CD & ADNUM)
End If
End If
PREVNO = ADNUM
Else
If InStr(C6, CURCH) > 0 Then
ADNUM = "6"
End If
End If
End If
'End If
'End If
'End If
If ADNUM = PREVNO And PR > 1 Then
If PREVCH = "V" Then
CD = (CD & ADNUM)
End If
Else
If InStr("123456", ADNUM) > 0 And PR > 1 Then
CD = (CD & ADNUM)
End If
End If
PREVNO = ADNUM
'End If
rst.Update
'Next
' Move to the next record and continue the same approach
rst.MoveNext
'Wend
Loop
End If
rst.Close
Set rst = Nothing
End Sub