Jan 10th, 2000, 05:10 PM
Please tell me what is wrong with this code.
I am getting a "Subscript out of range error"
Private Sub DBCombo3_Click(Area As Integer)
Dim db As Database
Dim rs As Recordset
Dim SQLString As String
Dim NameArray() As String
Dim x As Integer
On Error GoTo Error1:
Set db = dtaemployee.Database ' openDatabase '("Your Microsoft Access Database ")
SQLString = "SELECT DISTINCTROW Surname, Forname From Employee"
'This is a command that queries the database for the employee ID, Last Name and First Name
Set rs = db.OpenRecordset(SQLString)
'If the record does not exist then it tells me
If rs.BOF = True And rs.EOF = False Then
MsgBox ("Cannot find customer!")
Exit Sub
rs.Close
db.Close
Else
x = 1
For x = 1 To rs.RecordCount
NameArray(x) = rs.Fields("Surname") & "," & rs.Fields("Forname")
'Places the information into array
x = x + 1
Next x
DBCombo3.Text = NameArray(x)
rs.Close 'Close the Recordset
db.Close
End If
Exit Sub
Error1:
MsgBox Err.Description, vbCritical, Err.Number
End Sub
Thank you
Tony
tonyj@f-p.co.uk
I am getting a "Subscript out of range error"
Private Sub DBCombo3_Click(Area As Integer)
Dim db As Database
Dim rs As Recordset
Dim SQLString As String
Dim NameArray() As String
Dim x As Integer
On Error GoTo Error1:
Set db = dtaemployee.Database ' openDatabase '("Your Microsoft Access Database ")
SQLString = "SELECT DISTINCTROW Surname, Forname From Employee"
'This is a command that queries the database for the employee ID, Last Name and First Name
Set rs = db.OpenRecordset(SQLString)
'If the record does not exist then it tells me
If rs.BOF = True And rs.EOF = False Then
MsgBox ("Cannot find customer!")
Exit Sub
rs.Close
db.Close
Else
x = 1
For x = 1 To rs.RecordCount
NameArray(x) = rs.Fields("Surname") & "," & rs.Fields("Forname")
'Places the information into array
x = x + 1
Next x
DBCombo3.Text = NameArray(x)
rs.Close 'Close the Recordset
db.Close
End If
Exit Sub
Error1:
MsgBox Err.Description, vbCritical, Err.Number
End Sub
Thank you
Tony
tonyj@f-p.co.uk