Hello guys!

Can you help me this type of error?

Run-time error '8574':

The object 'Employee ID:' was not found

This is the code:

Private Sub cmdPreview_Click()

Dim rsq As New Recordset

rsq.Open "SELECT * FROM qRecord where EmpID = " & Val(txtEmpID.Text) & "", con, adOpenStatic, adLockReadOnly, addUnknown
    
If rsq.EOF = False Then
    MsgBox "No records to view.", vbInformation, "No Records"
Else

    With drTrans.Sections(2)
        .Controls(Label1.Caption) = rsq.Fields("EmpID")
        .Controls(Label2.Caption) = rsq.Fields("LastName") & "," & rsq.Fields("FirstName")
        .Controls(Label3.Caption) = rsq.Fields("Position")
        
    End With
    
    Set drTrans.DataSource = rsq
    
    drTrans.Show
End If
End Sub

well I can't see anything referring to an object Employee ID but I am thinking you probably need to move line 18 above line 11. not much point in trying to use drTrans until you have assigned it a value.

Assuming this is a DataReport, this type of error usually occurs when there is a mismatch between the DataEnvironment that was initially used to create the report, and the RecordSource that is used to populate the report at runtime. You should verify that you're using the right column names.

As a general rule, it's a good idea to explicitly name the columns in your SQL statement rather than use the wildcard '*' to return the columns you need. That way you can verify that the column names you're expecting match what the DataEnvironment originally specified.

Hope that helps! Good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.