If I DON'T put this lass MSGBOX in the code, it moves off my found record!!

B

BrianDP

Here's my code.. Open a form, and find the record number in Lcontrol!
lastcust. But that last Msgbox MUST be there or the script ceases to
function correctly.


Private Sub cmdaccount_Click()

Dim cc As Integer
Dim db As Database
Dim rst As Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("lcontrol")

rst.MoveFirst
cc = rst!lastcust
rst.Close

DoCmd.OpenForm "customer definition"
If Nz(cc) <> 0 Then
Forms("Customer definition").Recordset.FindFirst "cust_code = " & cc
End If

'VVVVVVV Right here, this msgbox, if I remove it, the script still
runs, but it does NOT open to CC. I suspect it
'VVVVVVV DOES open to cc, but then for some reason it moves off of
that record. Any clues?
MsgBox cc


End Sub
 
D

David W. Fenton

:
If Nz(cc) <> 0 Then
Forms("Customer definition").Recordset.FindFirst "cust_code = "
& cc
End If

Change that to:

If Nz(cc) <> 0 Then
With Forms("Customer definition").RecordsetClone
.FindFirst "cust_code = " & cc
If Not .NoMatch Then
If Forms("Customer definition").Dirty Then
Forms("Customer definition").Dirty = False
End If
Forms("Customer definition").Bookmark = .Bookmark
End If
End With
End If

That's a start. I'd never use the form's recordset for navigation.
Indeed, I'd never use the form's recordset for anything at all. It's
too finicky and problematic, in my estimation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top