Label versus Label

aziz rasul

Active member
Local time
Today, 01:54
Joined
Jun 26, 2000
Messages
1,935
I have 2 labels and a combo box i.e. Label1, Label2 and cboSurgeons

When double clicking Label1, you can edit-delete-add records in tblSurgeons. On closing the table, cboSurgeons is updated. Here's the code. cboSurgeons is bound on an ID values, e.g. 1, 2, 3, etc.

Code:
Private Sub Label1_DblClick(Cancel As Integer)

    DoCmd.OpenTable "tblSurgeons", acViewNormal, acEdit
    Me.cboSurgeons.SetFocus
    Me.cboSurgeons.Requery
    Me.Refresh

End Sub

Label2's caption property takes the firstname and surname from the update
event of cboSurgeons i.e.

Code:
Private Sub cboSurgeons_AfterUpdate()

    If IsNull(Me.cboSurgeons) = False Then
        Me.Label2.Caption = DLookup("Firstname", "tblSurgeons", "[SurgeonID] =" & Me.cboSurgeons) & " " & DLookup("Surname", "tblSurgeons", "[SurgeonID] =" & Me.cboSurgeons)
        Me.Label2.ForeColor = 0
    Else
        Me.Label2.ForeColor = -2147483633
    End If

End Sub

Here's the problem. When I double click Label1 and edit a record, how can I update the caption on Label2 assuming the firstname or surname has changed for the ID value in cboSurgeons?
 
For staters you shouldn't be adding the data directly to the table. Use a form , that is what they are for. Once the data has been added / edited you need to refresh the combobox and label. You should not need the Dlookup.

If your combobox is set up correctly, change the label to a textbox, alter the appearance to look like a label, then in the control source put

= cboSurgeons.column(1) & ", " & Me.cboSurgeons.column(2)

Dave
 
Thanks, I'll try that.
 

Users who are viewing this thread

Back
Top Bottom