2 questions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi guys,
I cannot seem to figure out two intermittant problems I am having.

1. I have a form recordsetclone and am looping throught the records,
occationally I get the error "NO CURRENT RECORD"
I have done a test on the "absolute position", it says -1 when it should be
0. But this does not happen everytime.

Here is my code in a button that opens the next form:

iSalesOrderID = Me.SalesOrderRef_TxnID

stDocName = "InvoiceCreator"
DoCmd.Close acForm, "SalesOrder", acSaveYes
stLinkCriteria = "[SALESORDERREF_TXNID]=" & iSalesOrderID
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , sType '** pass invoice
type to invoicecreator form

So, I have explicitly ordered the form closed before the next one is opened.
Some reason the object is still opened???

Thanks for any help!
David

Set rsClone = frm.RecordsetClone
With rsClone
Debug.Print "before position:" & .AbsolutePosition
If .EOF Then
MsgBox ("No Records for :" & frm.Name)
Else
Do While Not .EOF

.....

..MoveNext
Loop
.MoveFirst


The other problem is 1 have 2 forms that do different functions but the
source is the same table. So I have actions to close 1 file and open
another. The 2nd form edits the table recordset in load event. But
occationally I get an error that the object cannot be edited because it is
opened (from the other form not being closed properly)

Here is my code:
 
You can receive the No Current Record error under these conditions:
1. Your form is at the new record (not yet saved).
2. NoMatch is true after a Find on the form's RecordsetClone.
3. You are at BOF (beginning of file) or EOF (end of file).
4. You attempted to Move on a recordset with no records.
5. You attempted to read a value from a recordset that has no records.
6. You deleted a record in Access 2002 Service Patch 3 (bug).

This should work:
With frm.RecordsetClone
If .RecordCount > 0 Then
.MoveFirst
Do While Not .EOF
'do something
.MoveNext
Loop
End If
End With

Regarding your other issue, try explicitly saving the record in the first
firm
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Open "MyOtherForm"
DoCmd.Close acForm, Me.Name

Editing the record in Form_Open sounds too early, but you could try
inserting
DoEvents
to allow the code to finish closing the previous form.
 
Back
Top