"Can't go to specified record" error

G

Guest

I searched this error before posting - couldn't seem to find a solution for
me.

I have two synchronized combo boxes - cboFirst which contains branch
locations and cboFind which contains customers assigned to those branches.
Works fine until I choose a customer name from cboFind - it still populates
but once I choose a customer and tab to the next field it gives me this
error.

cboFirst afterupdate code:
Private Sub cboFirst_AfterUpdate()
cboFind.Requery
cboFind.SetFocus
End Sub

cboFind afterupdate Code:
Private Sub cboFind_AfterUpdate()
Me.Painting = False
DoCmd.GoToRecord , , acFirst
Do Until Me!COMPANY_NAME = Me!cboFind
DoCmd.GoToRecord , , acNext
If Me.Recordset.EOF Then Exit Sub
Loop
Me.Painting = True

End Sub

I also have this to populate the customer number after the name is chosen -
not sure if this might be the cause but this is the code:
Private Sub cboFind_Exit(Cancel As Integer)
Me.CUSTOMER_NUMBER.Value = Me.cboFind.Column(1) ' value of Y
End Sub

Thank you for any help!
 
R

ruralguy via AccessMonster.com

Change your AfterUpdate code to:
Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Me.RecordsetClone.FindFirst "[COMPANY_NAME] = '" & Me.cboFind & "'"
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
Me.CUSTOMER_NUMBER = Me.cboFind.Column(1)
'-- Are you sure this is Column(1) or should it be Column(0)
'-- The columns are zero based, the first column being Column(0)
End If
End Sub

And delete the Exit event code!
 
G

Guest

Thank you! The cboFind is working properly - I don't get any errors.
However, the customer number field is not being populated at all. Here's my
code:

Private Sub cboFind_AfterUpdate()
Me.RecordsetClone.FindFirst "[COMPANY_NAME] = '" & Me.cboFind & "'"
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
Me.CUSTOMER_NUMBER.Value = Me.cboFind.Column(1)
End If
End Sub

Private Sub cboFirst_AfterUpdate()
cboFind.Requery
cboFind.SetFocus
End Sub

cboFind record source is a query with 3 columns, customer number being the
second column in the query - the first column in the combo box. It should be
column 1 but I tried 0, 1 and 2 to no avail. Not sure what the deal is...?

Thank you again for your help!

ruralguy via AccessMonster.com said:
Change your AfterUpdate code to:
Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Me.RecordsetClone.FindFirst "[COMPANY_NAME] = '" & Me.cboFind & "'"
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
Me.CUSTOMER_NUMBER = Me.cboFind.Column(1)
'-- Are you sure this is Column(1) or should it be Column(0)
'-- The columns are zero based, the first column being Column(0)
End If
End Sub

And delete the Exit event code!
I searched this error before posting - couldn't seem to find a solution for
me.

I have two synchronized combo boxes - cboFirst which contains branch
locations and cboFind which contains customers assigned to those branches.
Works fine until I choose a customer name from cboFind - it still populates
but once I choose a customer and tab to the next field it gives me this
error.

cboFirst afterupdate code:
Private Sub cboFirst_AfterUpdate()
cboFind.Requery
cboFind.SetFocus
End Sub

cboFind afterupdate Code:
Private Sub cboFind_AfterUpdate()
Me.Painting = False
DoCmd.GoToRecord , , acFirst
Do Until Me!COMPANY_NAME = Me!cboFind
DoCmd.GoToRecord , , acNext
If Me.Recordset.EOF Then Exit Sub
Loop
Me.Painting = True

End Sub

I also have this to populate the customer number after the name is chosen -
not sure if this might be the cause but this is the code:
Private Sub cboFind_Exit(Cancel As Integer)
Me.CUSTOMER_NUMBER.Value = Me.cboFind.Column(1) ' value of Y
End Sub

Thank you for any help!

--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
R

ruralguy via AccessMonster.com

Hi Rachel,
I'm not sure what is going on. the .Value property is the defauly property
of most controls so you do not need to specify it. Me.CUSTOMER_NUMBER is the
same as Me.CUSTOMER_NUMBER.Value. Are you sure the CUSTOMER_NUMBER control is
named CUSTOMER_NUMBER? Could it be [CUSTOMER NUMBER] with a space? If so
then you need to enclose it in brackets as I have done.
Thank you! The cboFind is working properly - I don't get any errors.
However, the customer number field is not being populated at all. Here's my
code:

Private Sub cboFind_AfterUpdate()
Me.RecordsetClone.FindFirst "[COMPANY_NAME] = '" & Me.cboFind & "'"
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
Me.CUSTOMER_NUMBER.Value = Me.cboFind.Column(1)
End If
End Sub

Private Sub cboFirst_AfterUpdate()
cboFind.Requery
cboFind.SetFocus
End Sub

cboFind record source is a query with 3 columns, customer number being the
second column in the query - the first column in the combo box. It should be
column 1 but I tried 0, 1 and 2 to no avail. Not sure what the deal is...?

Thank you again for your help!
Change your AfterUpdate code to:
Private Sub cboFind_AfterUpdate()
[quoted text clipped - 44 lines]
 

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