Thanks for your help on this, however, I still have some
remaining problems with the function. I truly appreciate
it
if you could provide me some additional pointers. Here's
what happens...
The function below (between the ******s) throws the
following error:
"Object variable or With block variable not set (91)".
Here's what I trying to achieve:
- Until I added the function DAO.Recordset, the INSERT was
working just fine.
- In order to view the changes immediately (after the
INSERT was executed) in the
tblLocationHistory_subform, I used the "Me.Requery".
- The Me.Requery, however, forced me to "jump" back to the
1st record (instead of remaining on the current record)
- I then included the "RecordClone" function (between the
*****s). This initially seemed to work fine, but I not
realized that the "record" freezes" - particularly when
making on the 1st record.
Again, when I now change the "AsOfDate" and then exit the
field, the error listed above "Object variable..." is
thrown.
How do I need to modify the DAO.Recordset query, so that I
can do the following:
1. Use the Me.Requery when on the 1st record
2. Use the DAO.Record function when on any other record
but the 1st record
Thanks in advance,
Tom
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Private Sub AsOfDate_Exit(Cancel As Integer)
On Error GoTo Err_Location_Exit
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
'******
Dim rs As DAO.Recordset
If rs.RecordCount = 1 Then
Me.Requery
Else
Dim lngID As Long
With Me
lngID = .CorrespondenceID
.Requery
DoEvents
Set rs = .RecordsetClone
rs.FindFirst "[CorrespondenceID] = " &
lngID
If rs.NoMatch = False Then
.Bookmark = rs.Bookmark
End If
End With
End If
'******
End_Location_Exit:
Exit Sub
Err_Location_Exit:
MsgBox Err.Description & " (" & Err.Number & ")", _
vbOKOnly + vbCritical
Resume End_Location_Exit
End Sub
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
-----Original Message-----
Graham:
I like this approach... simple and straight-forward.
I now bypass the initial 3020 error; however, once the
first record is created, the screen/record freezes when I
run another function that allows me to
update/insert "current values" into a "history table".
This is how I modified the DAO function as you suggested
(I did not use the Exit sub though since other steps have
to be performed before I should exit out).
With the information given, do you have any idea why the
record still freezes at times. Or is the "Do Nothing"
approach not the best one to use?
Thanks in advance,
Tom
&&&&&&&&&&&&&&
If Me.RecordsetClone.RecordCount = 0 Then
'Do Nothing
Else
Dim rs As DAO.Recordset
Dim lngID As Long
With Me
lngID = .CorrespondenceID 'ensure to
synchronize naming convention of PK below []
.Requery
DoEvents
Set rs = .RecordsetClone
rs.FindFirst "[CorrespondenceID] = " &
lngID
If rs.NoMatch = False Then
.Bookmark = rs.Bookmark
End If
End With
End If
'****
-----Original Message-----
Hi Tom
I'm not sure how you're getting error 3020. I would
have expected a
"Invalid use of Null" error on the line:
lngID = .AutoNumberFieldName
However, the simplest solution would be not to requery
if there are no
records:
If Me.RecordsetClone.RecordCount = 0 then Exit Sub
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
Return mail address is invalid in a vain attempt to
reduce spam.
Feedback is welcome at: (e-mail address removed)
Please post new questions or followups to newsgroup.
Instead of using the "Me.Requery" on the form, I use
the
function below (****) for requerying the form.
This will allow me to "stay" on the current record
(after
requerying) instead of "jumping" back to the first
record.
I now realize, however, that the function throws an
error
if the table is completely empty and I requery the
first
record.
The error is: "Update or CancelUpdate without AddNew or
Edit" (error 3020).
Now, in the form's OnError event, I have put the
following:
If DataErr = 3020 Then
Response = acDataErrContinue
End If
... however, I now cannot change any other field values
in the form anymore.
Does anyone know how to either modify the function
below
or simply ignore the error message and allowing me to
continue to make changes to the 1st record?
Thanks in advance,
Tom
&&&&&&&&&&&&&&&&&&&&&&&&&
Object (DAO) 3.6 Library in the References Collection:
****
Dim rs As DAO.Recordset
Dim lngID As Long
With Me
lngID = .AutoNumberFieldName
.Requery
DoEvents
Set rs = .RecordsetClone
rs.FindFirst "[AutoNumberFieldName] = " & lngID
If rs.NoMatch = False Then
.Bookmark = rs.Bookmark
End If
End With
****
.
.