Here is a block of code that gets re-used with changes throughout my project. It takes various numeric values stored in a remote MySQL DB, munges them together to create drawing identifiers,
The above code works everywhere else, but in this iteration the last line for the htlist is present, but blank. Is this a code error, or could it be a corruption in the file itself?
Code:
Private Sub poplist()
Dim cn As ADODB.Connection
Dim cmd As ADODB.command
Dim rst As ADODB.Recordset
Dim i As Integer
Dim f(9) As String
Dim Field0 As String
Dim Field1 As String
Dim Field2 As String
Dim rev As Integer
Set cn = New ADODB.Connection
With cn
.ConnectionString = DB_CONNECT
.Open
End With
Set cmd = New ADODB.command
With cmd
.CommandType = adCmdUnknown
End With
[COLOR=green]'get fields to build drawing number[/color]
sqlstr = "SELECT h.ht_id, h.softver, h.House_type, "
sqlstr = sqlstr & "b.ShortCode AS builder_ShortCode, h.level, h.Floor, h.Revision, "
sqlstr = sqlstr & "d.ShortCode AS dist_ShortCode, e.ShortCode AS enq_ShortCode,"
sqlstr = sqlstr & " h.Hours"
sqlstr = sqlstr & " FROM `contacts`.`HouseType` AS h INNER JOIN CompShort as b"
sqlstr = sqlstr & " ON b.CompID = h.builder_id INNER JOIN CompShort as d"
sqlstr = sqlstr & " ON d.CompID = h.dist_id INNER JOIN CompShort as e"
sqlstr = sqlstr & " ON e.CompID = h.enq_id WHERE h.quote_id =" & QuoteID
sqlstr = sqlstr & " ORDER BY House_Type"
With cmd
.ActiveConnection = cn
.CommandText = sqlstr
Set rst = .Execute
End With
[COLOR=green]'clear out listbox for new items[/color]
For i = Me.HTlist.ListCount - 1 To 0 Step -1
Me.HTlist.RemoveItem i
Next i
If Not rst.EOF Then
rst.MoveFirst
Do
[COLOR=green]'loop through resultset[/color]
f(0) = rst.Fields(0) [COLOR=green]'Housetype ID for operatons[/color]
f(1) = rst.Fields(1) [COLOR=green]'Software version[/color]
For i = rst.Fields.Count - 1 To 2 Step -1
If IsNull(rst.Fields(i)) Then
f(i) = ""
ElseIf rst.Fields(i) = "non" Then
f(i) = ""
ElseIf i = 6 Then
If rst.Fields(i) = 0 Then
f(i) = ""
Else
rev = rst.Fields(i)
f(i) = "=rev-" & Chr(96 + rev)
End If
Else
f(i) = "=" & rst.Fields(i)
End If
Next i
Field0 = rst.Fields(2) 'House name
Field1 = f(1) & f(3) & f(4) & f(2) & f(5) & f(6) & f(7) & f(8) [COLOR=green]'Drawing number identifier[/color]
Field2 = Nz(rst.Fields(9), "0") [COLOR=green]'Hours assigned to project[/color]
Me.HTlist.AddItem Item:="" + f(0) + ";" + Field0 + ";" + Field1 + ";" + Field2 + ""
rst.MoveNext
Loop Until rst.EOF
End If
cn.CLose
End Sub
The above code works everywhere else, but in this iteration the last line for the htlist is present, but blank. Is this a code error, or could it be a corruption in the file itself?