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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Label = Query Field on Unbound Form 1

Status
Not open for further replies.

dcurtis

Technical User
May 1, 2003
273
US
I have an unbound (with all unbound controls) startup form. On that form I would like a label's caption equal a field from a query. I tried setting the label.caption property but I can't seem to make it work.

Then I tried to use a text box on the form and point it to the query field, but I keep getting a #Name? error.

Next I tried to set the Form's record source to the query, and just add that field. Worked great unless the query returned no value, which will happen about 30% of the time, then nothing on the form was visible......

Any ideas?

TIA for any help.

----
Access 2002 on a mixed Windows OS network.
 
Try Something like this:

Private Sub Form_Open(Cancel As Integer)
Dim db As DAO.Database, rst As DAO.Recordset
Set db = Currentdb
Set rst = db.OpenRecordSet("YourQueryName")
If rst.RecordCount>0 Then
With rst
.MoveFirst
Me.LabelName.Caption = rst!FieldNameHere
End With
End If
End Sub

PaulF
 
Worked like a charm. Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top