Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update label with query results

Status
Not open for further replies.

Kindi

Programmer
Jan 31, 2001
54
0
0
GB
Hi

When a user enters in text in 2 text boxes on a form, i wish them to click a validation button. The validation button will then run a query and the query will comprise of information added in the text boxes above, the results will then appear on the same form on a label.

To do this a tek-tips master advised me to do this:

Two text boxes 1 & 3 and a label 5 on a form and:

Private Sub Command6_Click()
Dim SQL As String, db As DAO.Database, rs As DAO.Recordset

Set db = CurrentDb()

SQL = "SELECT * FROM Artist WHERE ArtistID = "
SQL = SQL & Val(Me.Text0) & " OR " & Val(Me.Text2) & ";"
' MsgBox SQL

Set rs = db.OpenRecordset(SQL)

Me.Label5.Caption = rs![artist]
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing

End Sub


I have done all as required above, but i then get this error message on the code area:

Compile Error:
User-Defined type not defined

and the code "As DAO.Database" is highlighted in blue.

Im not sure what to do, or can i use another piece of code?

Cheers
 
Hi,

Sounds like your problem could be with references - Access doesn't ref DAO by default, you need to do it manually.

In case you're not sure how to do this...
1. On the menu bar go to tools -> references
2. Scroll down until you see Microsoft DAO 3.6 (could be a lower # with earlier versions), click on the check box
3. Hit the priority up arrow until it is above the Microsoft ActiveX Data Obj reference
4. Hit OK

With any luck, this should solve the problem,
CJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top