Full Version: subform update with sql tables
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
mkcat
I am trying to help a friend with their project.
Database was converted from 2003 to 2007 with SQL backend.
I know nothing about SQL.
I have only started on 2007.

I have the main form called "classes with subform called "grades"
Data on the main form is correct.
Main form is continuous form.
When I click on a mainform record (the plus sign), the subform open.
Only the very first time when I click to open the subform is the data displayed correct.
If I then click on another main form record, the data is not correct for the subform data it brings up.

Only if I click on the primary key number on the form, then click on the plus to
open the subform will the data be correct on the subform.

Checked the master/child and the fields are correct.

Any suggestions on what to check next?




Manystrengths
I would examine your events, particualry the onchange event.

Can you copy and paste both your main and sub forms' code? I might be able to help more if I can see which procedures fire and when.

Hope this helps.

mkcat
Thanks, ManyStrengths
Any help is greatly appreciated!

Code:
FORM

Option Compare Database
Option Explicit

Private Sub Form_DataChange(ByVal Reason as Long)
DoCmd.RunCommand acCmdRefresh
[Q0 subform].Requery
End Sub

Private Sub Location_Change()
If Location] <> “abc” Then
Room_ = “NA”
End If
End Sub

Private Sub Q0_subform_Enter()
DoCmd.RunCommand acCmdRefresh
End Sub

Private Sub Room__GotFocus()
Room_.RowSource = “SELECT DISTINCT Rooms.Room_Num FROM Rooms WHERE
(((Rooms.C_Number) = [Forms]![All_DB]![Classes
subform].[Form]![C_Number]));”
Room_.Requery
End Sub


SUBFORM
Option Compare Database
Option Explicit

Private Sub Form_Load()
DoCmd.Requery
DoCmd.RunCommand acCmdRefresh
End Sub

Private Sub Form_Query()
‘DoCmd.Requery
Me.RecordSource = “SELECT Grades.SSN, Grades.Class_ID, Grades.New_hire,
Grades.Grade, Grades.[Certified?],Grades.Contact, Grades.Change_Date,
Grades.Post_Name, Grades.Notes, Students.L_name, Students.F_name FROM
Students INNER JOIN Grades ON Students.SSN = Grades.SSN ORDER BY
Students.L_name;”
DoCmd.RunCommand acCmdRefresh
End Sub


These are from the Recordsource for the forms.
Form
SELECT DISTINCTROW Classes.C_number, Classes.Instructor, Classes.Instructor2, Classes.C_Start_Date, Classes.C_end_Date, Classes.Location,Classes.Room_Num,Classes.Notes,Classes.Class_ID, Classes.C_type FROM Classes ORDER BY Classes.C_Start_date DESC;

SubForm
Me.RecordSource = “SELECT Grades.SSN, Grades.Class_ID, Grades.New_Hire, Grades.Grade, Grades.[Certified?], Grades.Contact,Grades.Change_date,Grades.Post_Name,Grades.notes, Students.L_name,Students.F_name FROM Students INNER JOIN Grade ON Students.SSN = Grades.SSN ORDER BY Students.L_name;

I have tried adding
Forms![Classes]![Q0_subform.class_id].form.requery into the main form afterupdate event

And have tried adding this to Q0_subform_enter()

me.recordsource = “select grades.ssn, grades.class_id…” {the whole select statement}
docmd.requery

Mel
Manystrengths
On first glance, and by no means a thorough review, I see this sub as a potential problem....

CODE
Private Sub Form_Query()
‘DoCmd.Requery
Me.RecordSource = “SELECT Grades.SSN, Grades.Class_ID, Grades.New_hire,
Grades.Grade, Grades.[Certified?],Grades.Contact, Grades.Change_Date,
Grades.Post_Name, Grades.Notes, Students.L_name, Students.F_name FROM
Students INNER JOIN Grades ON Students.SSN = Grades.SSN ORDER BY
Students.L_name;”
DoCmd.RunCommand acCmdRefresh
End Sub


You Could try this instead...... BE SURE TO BACK UP YOUR CODE.
CODE
Private Sub Form_Query()
Dim myrst As String
myrst = "SELECT Grades.SSN,Grades.Class_ID, Grades.New_hire,Grades.Grade, Grades.[Certified?],Grades.Contact, Grades.Change_Date,Grades.Post_Name, Grades.Notes, Students.L_name, Students.F_name FROM Students INNER JOIN Grades ON Students.SSN = Grades.SSN ORDER BY Students.L_name;"
Me.RecordSource = myrst
Forms![Your Sub Form Name].Requery
End Sub



THIS IS AIR CODED..... you'll likely have to tweak it.

If I'm reading your code correctly, it appears that the following is the trigger for the sub form...... Check your method... there's likely a better way to trigger the sub form. I would use the main form's on change event.
CODE
Private Sub Q0_subform_Enter()
DoCmd.RunCommand acCmdRefresh
End Sub


An example of an onchange event below.... AGAIN AIR CODED.... so you will likely have to tweak for your needs.

CODE
Private Sub Form_DataChange
Set rst = Me.RecordsetClone
rst.FindFirst "Forms![Your Sub Form Name].[Students.SSN] = " & Str(Me![Students.SSN])
If rst.NoMatch Then
MsgBox "No Sub Form records found"
Else
Me.Bookmark = rst.Bookmark
End If
rst.Close
End Sub


Give a few things a try..... BACKUP your code....

Sincerely hopes this helps...... Hopefully some others will chime in on it as well. I'm much better help with having the database open on my screen, but that's not always ideal. However, there are many talented gurus here that should be able to add to my comments and get you going in the right direction.


mkcat
Thank you, ManyStrengths

I will try your suggestions and see where that gets me.

compute.gif




This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.