G
Guest
I have a form bound to a single table, with 2 combo boxes. The first combo
box uses a simple query based on the same table as it's row source (uses
SELECT DISTINCT). After a selection is made in the 1st combo box, a query is
run and the second comboBox rowsource is based on the results of that query.
All this works fine and the correct records are displayed in the form and
subform. The problem comes when I try to edit data on the form. No matter
what record I'm on when I make the edits, the edits are always saved to the
first record, and any further edits will just continue to overwrite the data
for the first record. I can navigate to the correct records by using the
combo boxes, but why will it not save data to the record I'm on when I make
the edits???
I've read that a query that uses the DISTINCT keyword is not updateable- but
this query is only used as a row source for one of the comboBoxes, the Form
is actually bound to a single table- could this Non updateable query be
what's causing the problem in updating the table?
I think I recall having this problem once before on a database that was very
similar to this one, and I spent weeks reading these discussion boards before
I finally found a solution. Now I can't remember what in the world it was to
save my life, and in the last few days I've not been able to find anything
similar to this in the discussion boards. Does anyone have any ideas??? The
AfterUpdate code for the comboBoxes as well as my cmdSaveChanges code is
listed below:
Private Sub cboTestDescription_AfterUpdate()
DoCmd.OpenQuery "qryTestLab", acViewNormal, acReadOnly
If "qryTestLab" = "" Then
Me.cboLabName.RowSource = "Select tblOutsideLabListing.[Lab Name]
FROM [tblOutsideLablisting]" _
& "ORDER BY tblOutsideLabListing.[Lab Name]"
End If
DoCmd.Close acQuery, "qryTestLab"
cboLabName.Requery
End Sub
Private Sub cboLabName_AfterUpdate()
Dim rs As DAO.Recordset
Set rs = Me.Recordset.Clone
rs.FindFirst "[Test Description] &[Lab Name] = '" &
Me![cboTestDescription] & Me![cboLabName] & "'"
Me.Bookmark = rs.Bookmark
Me.[Lab Name] = Me.cboLabName
fsubOutsideLabListing.Visible = True
Me.Refresh
fsubOutsideLabListing.Requery
End Sub
Private Sub cmdSaveChanges_Click()
On Error GoTo Err_cmdSaveChanges_Click
Me.txtLastUpdate = Date
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_cmdSaveChanges_Click:
Exit Sub
Err_cmdSaveChanges_Click:
MsgBox Err.Description
Resume Exit_cmdSaveChanges_Click
End Sub
Thank you for any assistance
box uses a simple query based on the same table as it's row source (uses
SELECT DISTINCT). After a selection is made in the 1st combo box, a query is
run and the second comboBox rowsource is based on the results of that query.
All this works fine and the correct records are displayed in the form and
subform. The problem comes when I try to edit data on the form. No matter
what record I'm on when I make the edits, the edits are always saved to the
first record, and any further edits will just continue to overwrite the data
for the first record. I can navigate to the correct records by using the
combo boxes, but why will it not save data to the record I'm on when I make
the edits???
I've read that a query that uses the DISTINCT keyword is not updateable- but
this query is only used as a row source for one of the comboBoxes, the Form
is actually bound to a single table- could this Non updateable query be
what's causing the problem in updating the table?
I think I recall having this problem once before on a database that was very
similar to this one, and I spent weeks reading these discussion boards before
I finally found a solution. Now I can't remember what in the world it was to
save my life, and in the last few days I've not been able to find anything
similar to this in the discussion boards. Does anyone have any ideas??? The
AfterUpdate code for the comboBoxes as well as my cmdSaveChanges code is
listed below:
Private Sub cboTestDescription_AfterUpdate()
DoCmd.OpenQuery "qryTestLab", acViewNormal, acReadOnly
If "qryTestLab" = "" Then
Me.cboLabName.RowSource = "Select tblOutsideLabListing.[Lab Name]
FROM [tblOutsideLablisting]" _
& "ORDER BY tblOutsideLabListing.[Lab Name]"
End If
DoCmd.Close acQuery, "qryTestLab"
cboLabName.Requery
End Sub
Private Sub cboLabName_AfterUpdate()
Dim rs As DAO.Recordset
Set rs = Me.Recordset.Clone
rs.FindFirst "[Test Description] &[Lab Name] = '" &
Me![cboTestDescription] & Me![cboLabName] & "'"
Me.Bookmark = rs.Bookmark
Me.[Lab Name] = Me.cboLabName
fsubOutsideLabListing.Visible = True
Me.Refresh
fsubOutsideLabListing.Requery
End Sub
Private Sub cmdSaveChanges_Click()
On Error GoTo Err_cmdSaveChanges_Click
Me.txtLastUpdate = Date
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_cmdSaveChanges_Click:
Exit Sub
Err_cmdSaveChanges_Click:
MsgBox Err.Description
Resume Exit_cmdSaveChanges_Click
End Sub
Thank you for any assistance