0

Hi Guys and Lassies,
Currently creating a program and need one bit of info to complete.
Using really simple code (Not SQL) I want to select a name from a dropdown combo, and once selected, displays the name in a label, AS WELL as displaying relevant info from a database table in two other labels (ie The database has columns name, age and telephone number. I click on the name from a dropdown and the form displays name age and telephone number on the form)

Can someone please reply. I would really appreciate your expert help on this.

Kenny,
Scotland.

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by dspnhn
0

try this

'this is using DAO 3.6 object library and access 2003
Dim db As Database
Dim rs As Recordset

Private Sub cmbnm_Click()
If cmbnm.Text <> "" Then
If rs.RecordCount > 0 Then
rs.Index = "nm"
rs.Seek "=", Trim(cmbnm.Text)
If rs.NoMatch = False Then
lblage.Caption = rs!age
lblphone.Caption = rs!phone
End If
End If
Else
MsgBox "Please select from combox first", vbInformation, "error"

End If

End Sub

Private Sub Form_Load()
Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2

Set db = OpenDatabase(App.Path & "\db1.mdb")

loadname
End Sub

Private Sub loadname()
Set rs = db.OpenRecordset("table1")
If rs.RecordCount > 0 Then
rs.MoveFirst
cmbnm.Clear
Do While rs.EOF <> True
cmbnm.AddItem Trim(rs!Name)
rs.MoveNext
Loop

Else
MsgBox "No records found", vbInformation, "Error"
End If
End Sub

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.