normally I use as suggested access to handle forms and it works perfect.
However I was wondering how to create it with recordset.
Here is a code snippet what I have in Form1
Code:
Dim db As Database
Dim rst As Recordset
Private Sub Form_Load()
Set db = CurrentDb
Set rst = db.OpenRecordset("qryTenants", dbOpenDynaset, dbSeeChanges)
Do Until rst.EOF
Me.lstTenant.AddItem rst!SurName
rst.MoveNext
Loop
rst.MoveFirst
RefreshData
End Sub
Private Sub RefreshData()
If Not rst.BOF And Not rst.EOF Then
Me.txtTenantID = rst!TenantID
Me.txtSalutionID = rst!SalutionID
Me.txtFirstName = rst!FirstName
Me.txtSurName = rst!SurName
Me.txtTenantName = rst!TenantName
Me.txtDOB = rst!DOB
Me.txtAddress = rst!Address
Me.txtTown = rst!Town
Me.txtPostcode = rst!Postcode
Me.txtCountryID = rst!CountryID
End If
End Sub
Private Sub btnFirstRecord_Click()
rst.MoveFirst
RefreshData
End Sub
Private Sub btnPreviousRecord_Click()
If Not rst.BOF Then
rst.MovePrevious
RefreshData
End If
End Sub
Private Sub btnNextRecord_Click()
If Not rst.EOF Then
rst.MoveNext
RefreshData
End If
End Sub
Private Sub btnLastRecord_Click()
rst.MoveLast
RefreshData
End Sub
This code example I used is from Steve Bishop:
Are you asking how to select values from a combo with code? The answer is - you must hard-code the selection since you have no user to pick from a list. AND, that means that if the combo shows text but stores an ID, then you must populate the combo with the ID value and NOT the text value.
Just for my understanding how would you need to work with recordest if there are more tables involved as tblCountry to pick a Country within the form from a combobox. And likewise with Salution.
I understand that this is more work but was just wondering how to do it not for any billing purpose ;-)
Just for my own usage and to understand it better.
And why would you use recordsets in the first place as it is more work?
What are the benifits to do so?
There are tutorials and so forth for using recordest in unbound forms but as far as I found tutorials there where always simple tables used with no relationships.