Hi Simon
Sorry, but you still haven't answered two important questions:
1. What are the link fields between the main form and the subform?
I'm guessing that LinkMasterFields is cboEmpName and LinkChildFields is
Employees_ID. Is this correct?
2. What exactly do you mean by "the Requery is loading data from the
previous record instead of the current record"? Do you mean that the
subform shows the courses for a different employee from the one you have
displayed in the main form? Or does the main form change to another record?
Also, remember last week in my answer to you about junction tables I said:
Often the junction table contains only those two fields, but sometimes it
may be appropriate to store additional data there. This must happen ONLY
if
the data are attributes of the COMBINATION of the two foreign keys. For
example, the date enrolled, date completed, and final result are all
attributes of the combination of employee and course.
It appears that you are storing in your junction table the employee's name
and the Doc_Number. The Employee's name is an attribute of the employee,
not the junction, so it should not be in that table at all. Also, I suspect
the same applies to Doc_Number, which is an attribute of the course. Both
these fields are available by creating a query joining the three tables.
It is very rarely appropriate to copy fields from the one-side table into
the many-side table. One example where this is necessary is in an order
entry application, where the price of a product *at the time of the order*
needs to be recorded. In that sense, the price has become an attribute of
the *product ordered*, not just of the product.
Also, some comments on your code:
1. Instead of a "Select *" query, just open the table directly:
Set rs = db.OpenRecordset("EmployeeCourseJoin", dbOpenDynaset)
2. If you want to go to the trouble of setting a control variable to refer
to your listbox, then use it. Either replace all instances of "lstAdmin" or
"Me.lstAdmin" by "ctl" or (better) just refer to lstAdmin directly and get
rid of "ctl".
Answer back about the questions above and we'll try to resolve the Requery
problem.
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
Simon said:
Hi Graham,
I'm doing the requery on a subform who's Record Source is a table named:
EmployeeCourseJoin
Following is the code being used:
Dim rs As Recordset, db As Database, sql As String
Dim SelectedItem As Variant
Dim ctl As Control
sql = "Select * From EmployeeCourseJoin"
Set db = CurrentDb
Set rs = db.OpenRecordset(sql, dbOpenDynaset)
Set ctl = Me.[lstAdmin]
For Each SelectedItem In lstAdmin.ItemsSelected
rs.AddNew
rs![Training Courses_ID] = Me.lstAdmin.Column(0, SelectedItem)
rs![Employees_ID] = Me.cboEmp_Name.Value
rs("Emp_Name") = Me.cboEmp_Name.Column(1)
rs("Doc_Number") = Me.lstAdmin.Column(1, SelectedItem)
rs.Update
ctl.Selected(SelectedItem) = False
Next
rs.Close
Set db = Nothing
Set rs = Nothing
'Refresh the display
Me.sfrmAdmin.Requery
End Sub
Graham Mandeno said:
Hi Simon,
Please provide some more information.
What are you requerying? The main form? The subform? A control?
If it's a form (main or sub), what is the RecordSource of that form?
If it's a subform, what are the link fields?
When you say "the previous" record, do you mean the previous record on
the
main form?
--
Graham Mandeno [Access MVP]
Auckland, New Zealand
Hello Again,
I am saving data to a table and reloading it into a subform afterwards.
The
problem is the "Requery" is loading data from the previous record
instead
of
the current record.
Q. How do I point to current record before issuing the ReQuery.
-Simon