Recordset not working

G

graeme34

Hi could anybody help me?
I am trying to use the following code to populate a forms controls from a
combo box, the code from the combo box after update is as follows

Private Sub cboMoveTo_AfterUpdate()

Dim rs As DAO.Recordset

If Not IsNull(Me.cboMoveto) Then
'Save before move.
If Me.Dirty Then
Me.Dirty = False
End If
'Search in the clone set.
Set rs = Me.RecordsetClone
'Stop
rs.FindFirst "[AccountIndex] = """ & Me.cboMoveto & """"

'Display the found record in the form.

Me.Bookmark = rs.Bookmark
'Stop
rs.Close
End If
End Sub

I have placed a couple of stop statements to test where it was going wrong it
seems the recordset is not working as the absolute position is = -1. Yet I
have used similar code in another form and it worked fine.....??? Any help
would be greatly appreciated.
Graeme
 
B

Brian Bastl

Don't know if it matters, but is cboMoveTo located in the form's header or
in the detail section?

Brian
 
G

graeme34

Hi Brian

Thanks for your interset... cboMoveTo is in the forms header, although it was
also in the header of another form and that worked??


Brian said:
Don't know if it matters, but is cboMoveTo located in the form's header or
in the detail section?

Brian
Hi could anybody help me?
I am trying to use the following code to populate a forms controls from a
[quoted text clipped - 27 lines]
would be greatly appreciated.
Graeme
 
B

Brian Bastl

Graeme,

The coding looks fine to me with the exception of a typo. The sub is:

Private Sub cboMoveTo_AfterUpdate(),

rs.FindFirst "[AccountIndex] = """ & Me.cboMoveto & """"

Me.cboMoveto should be Me.cboMoveTo with a capital T.

Also, is the bound column text or numeric? If the latter, then it'd read:
rs.FindFirst "[AccountIndex]=" & Me.cboMoveTo

Does this help?

Brian


graeme34 said:
Hi Brian

Thanks for your interset... cboMoveTo is in the forms header, although it was
also in the header of another form and that worked??


Brian said:
Don't know if it matters, but is cboMoveTo located in the form's header or
in the detail section?

Brian
Hi could anybody help me?
I am trying to use the following code to populate a forms controls from
a
[quoted text clipped - 27 lines]
would be greatly appreciated.
Graeme
 
G

graeme34 via AccessMonster.com

Hi Brian (again)

The bound column is a text field. Its not the coding that seems to be the
problem its the fact, the form does not seem to be creating a recordset.
When updating the combo box I am getting the runtime error '3021' 'no current
record'

Thanks again for your interset.
Graeme

Brian said:
Graeme,

The coding looks fine to me with the exception of a typo. The sub is:

Private Sub cboMoveTo_AfterUpdate(),

rs.FindFirst "[AccountIndex] = """ & Me.cboMoveto & """"

Me.cboMoveto should be Me.cboMoveTo with a capital T.

Also, is the bound column text or numeric? If the latter, then it'd read:
rs.FindFirst "[AccountIndex]=" & Me.cboMoveTo

Does this help?

Brian
[quoted text clipped - 11 lines]
 
B

Brian Bastl

Well, I don't know then. I copied your code into a test db, and simply
changed the field and control names. Worked just fine for me.

Are you sure that [AccountIndex] isn't a numeric field?

Brian


graeme34 via AccessMonster.com said:
Hi Brian (again)

The bound column is a text field. Its not the coding that seems to be the
problem its the fact, the form does not seem to be creating a recordset.
When updating the combo box I am getting the runtime error '3021' 'no current
record'

Thanks again for your interset.
Graeme

Brian said:
Graeme,

The coding looks fine to me with the exception of a typo. The sub is:

Private Sub cboMoveTo_AfterUpdate(),

rs.FindFirst "[AccountIndex] = """ & Me.cboMoveto & """"

Me.cboMoveto should be Me.cboMoveTo with a capital T.

Also, is the bound column text or numeric? If the latter, then it'd read:
rs.FindFirst "[AccountIndex]=" & Me.cboMoveTo

Does this help?

Brian
[quoted text clipped - 11 lines]
would be greatly appreciated.
Graeme
 
S

stefan hoffmann

hi,
Set rs = Me.RecordsetClone
rs.FindFirst "[AccountIndex] = """ & Me.cboMoveto & """"
'Display the found record in the form. If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
Else
MsgBox "No matching record found."
End If
'Stop
rs.Close

mfG
--> stefan <--
 
B

Brian Bastl

Have you looked here?

http://support.microsoft.com/kb/200650/en-us

Brian


graeme34 via AccessMonster.com said:
Hi Brian (again)

The bound column is a text field. Its not the coding that seems to be the
problem its the fact, the form does not seem to be creating a recordset.
When updating the combo box I am getting the runtime error '3021' 'no current
record'

Thanks again for your interset.
Graeme

Brian said:
Graeme,

The coding looks fine to me with the exception of a typo. The sub is:

Private Sub cboMoveTo_AfterUpdate(),

rs.FindFirst "[AccountIndex] = """ & Me.cboMoveto & """"

Me.cboMoveto should be Me.cboMoveTo with a capital T.

Also, is the bound column text or numeric? If the latter, then it'd read:
rs.FindFirst "[AccountIndex]=" & Me.cboMoveTo

Does this help?

Brian
[quoted text clipped - 11 lines]
would be greatly appreciated.
Graeme
 
D

Dirk Goldgar

graeme34 via AccessMonster.com said:
Hi Brian (again)

The bound column is a text field. Its not the coding that seems to be
the problem its the fact, the form does not seem to be creating a
recordset. When updating the combo box I am getting the runtime error
'3021' 'no current record'

Check the form's RecordSource property. Is it a table, stored query, or
SQL statement? If it's a query, whether stored or in-line SQL, what is
the SQL of the query? Does the query return any records? Can you
verify that the AccountIndex you're looking for exists in the form's
recordset? Is the form's Data Entry property set to True, by any
chance?
 
G

graeme34 via AccessMonster.com

Hi Dirk,
Thanks for your message, slight oversight by me, the forms data entry
property was set to true. Works fine now it is set to false.
Thank you.
Graeme
 

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