-----Original Message-----
1. Like I suspected, the problem is that everyone's
advice from the info you posted was aimed at re-querying
the main Form which messed thing up. If you go back to my
previous posts, I was wondering why you re-queried (the
Form) using the Textbox_Exit Event.
2. All you need to do is to add a few lines of code to re-
query the Subform rather than the Main form.
3. I would normally use the AsOfDate_AfterUpdate Event
but Exit Event should be OK. Continuing with your first
bit of code, you need:
....
CurrentDb().Execute strSQL, dbFailOnError
DBEngine.Idle dbRefreshCache
Me.{SubformControlName}.Form.Requery
****
1. Delete the rest of the code except for the exit & the
error-trapping.
2. You need to replace {SubformControlName} with the
actual name in your Form/Subform. If you re-read my
previous post, I am sure you would notice that I stressed
the importance of the SubformControl Name.
HTH
Van T. Dinh
MVP (Access)
-----Original Message-----
Van:
Again, thanks for your help. I truly appreciate it!
To provide to more information, please allow me to give
first you an overview of what I trying to achieve.
PURPOSE:
On a MAIN FORM (frmCorrespondence), there are 2 fields
(LOCATION = textbox, AS_OF_DATE = date field) which
values will change over the course of a document's "life
cycle". A document is passed through the organization
and we need to be in the position to trace a) its current
location and b) all of its previous locations and their
dates.
PROCESS:
On the frmCorrespondence (main form), I have linked the
AS_OF_DATE field to a function will will insert
the "current"
LOCATION AND AS_OF_DATE values into a table called
tblLocationHistory. The functionality of this process
works
just fine.
The tblLocationHistory resides as a subform (I pressed F11
and simply dragged the table on the frmCorrespondence).
[I believe the sub form is "linked" to the main form).
If I now change the AS_OF_DATE, the AfterExit
event "kicks" in and inserts the location and date values
into the
tblLocationHistory. And this is where the problem
lies... the newly inserted records are NOT visible in the
subform
unless I either a) move to another previous/next record
and then record to the current record, or b) close the
frmCorrespondence and re-open it.
At this time, let me provide you the entire function that
linked to the MAIN FORM's properties. I have marked
the comment lines with an "@" to allow you to quickly
identify some potentially useful comments.
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Private Sub AsOfDate_Exit(Cancel As Integer)
On Error GoTo Err_Location_Exit
***** INSERT works fine ******
'@ 'This will insert the current Location and date values
into the "location history table"
strSQL = "Insert into tblLocationHistory
(CorrespondenceID, Disposition, Location, AsOfDate) " &
vbCrLf & _
"VALUES ('" & Format(Me!
CorrespondenceID.Value, "00000") & "', '" & Me!
Disposition.Value & "', '" & Me!Location.Value & "', #" &
Format(AsOfDate) & "#)"
MsgBox strSQL, , "Location history table will be
updated!"
CurrentDb().Execute strSQL, dbFailOnError
***** PROBLEM AREA ******
'@ ' This is where I requery the form/subform. I really
need to only refresh the subform (tblLocationHistory) since
'@ ' this is where the changes should be visible in "real-
time"
'@ ' With the EXCEPTION of the 1st record, I do see the
changes immediately in the subform (although it was the
main
'@ ' form that was refreshed).
'@ ' PROBLEM: When executing the INSERT function (after
changing and exiting the date field), the next time I may
'@ ' make changes to any other textfield/combo box, that
partilur textbox/combo box is THEN LOCKED... actually the
'@ ' entire record is locked up. When closing the
frmCorrespondence's window, a dialog box shows up that
indicates
'@ ' that the changes of the current record (record #1)
cannot be saved.
Dim rs As DAO.Recordset
Dim lngID As Long
With Me
lngID = .CorrespondenceID
.Requery
Set rs = .RecordsetClone
If rs.RecordCount > 1 Then
'DoEvents ' <<<<<< not sure if this would be
necessary
rs.FindFirst "CorrespondenceID = " & lngID
If rs.NoMatch = False Then .Bookmark =
rs.Bookmark
End If
End With
End_Location_Exit:
Exit Sub
Err_Location_Exit:
MsgBox Err.Description & " (" & Err.Number & ")", _
vbOKOnly + vbCritical
Resume End_Location_Exit
End Sub
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
PROPERTIES - MAIN FORM (frmCorrespondence):
Location field:
- resides on frmCorrespondence
AsOfDate field:
- resides on frmCorrespondence
- linked to the function above [Private Sub AsOfDate_Exit
(Cancel As Integer)]
PROPERTIES - SUB FORM (frmLocationHistory_Subform):
- contains the same identical fields (CorrespondenceID,
Location, AsOfDate) as the main form
- resides as a subform on frmCorrespondence
Quick recap:
- Subform needs to be refreshed/requeryed after the INSERT
into tblLocationHistory occurred
- DAO.Recordset works fine EXCEPT for the 1st record.
The textboxes on the main form lock up
when changes are made after the INSERT occurred on the
1st record.
Van, I truly hope that I have provided you sufficient
information to further analyze this problem.
Please let me know if you have any additional questions!
Thanks,
Tom
.