By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,501 Members | 2,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,501 IT Pros & Developers. It's quick & easy.

Combo Box Problem

P: n/a
I have a table (tblPhone) with text fields FULL, LAST, PHONE,

I also have a combo box (cmboFull) .
The row source for cmboFull is SELECT DISTINCT [FULL] FROM tblPhone;

Here's the code for the combo box

Private Sub cmboFull_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Full] = '" & Me![cmboFull] & "'"
Me.Bookmark = rs.Bookmark
This combo box populates ok but when I click on any item in the combo box I
get the following error on the "Set rs = Me.Recordset.Clone" statement.
Run time error '91'
Object variable or Withblock variable not set.

I used similar code in another program and it worked fine so I am puzzled
why it fails here.

Any ideas

The overall objective is to present a combo box containing the data in the
FULL field and
then set a couple of text boxes with the LAST and FULL fields in the
selected record.
Jun 5 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Try without the 2nd dot, i.e.:
Set rs = Me.RecordsetClone

There are several other things that could go wrong with that code, including
reference priorities, the need to test NoMatch, and weird messages if the
record cannot be saved to activate the move (e.g. "Cannot Update without
Edit first".) For an example of a FindFirst that takes care of these issues,
see:
http://allenbrowne.com/ser-03.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"RICHARD BROMBERG" <no*****@att.net> wrote in message
news:YT********************@bgtnsc05-news.ops.worldnet.att.net...
I have a table (tblPhone) with text fields FULL, LAST, PHONE,

I also have a combo box (cmboFull) .
The row source for cmboFull is SELECT DISTINCT [FULL] FROM tblPhone;

Here's the code for the combo box

Private Sub cmboFull_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Full] = '" & Me![cmboFull] & "'"
Me.Bookmark = rs.Bookmark
This combo box populates ok but when I click on any item in the combo box
I
get the following error on the "Set rs = Me.Recordset.Clone" statement.
Run time error '91'
Object variable or Withblock variable not set.

I used similar code in another program and it worked fine so I am puzzled
why it fails here.

Any ideas

The overall objective is to present a combo box containing the data in the
FULL field and
then set a couple of text boxes with the LAST and FULL fields in the
selected record.

Jun 5 '06 #2

P: n/a
Allen

I changed the code, removing the 2nd dot as you suggested, but that
generated the following error:
"You entered an expression that has an invalid reference to the
RecordsetClone property"

What else could be causing it.
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44***********************@per-qv1-newsreader-01.iinet.net.au...
Try without the 2nd dot, i.e.:
Set rs = Me.RecordsetClone

There are several other things that could go wrong with that code, including reference priorities, the need to test NoMatch, and weird messages if the
record cannot be saved to activate the move (e.g. "Cannot Update without
Edit first".) For an example of a FindFirst that takes care of these issues, see:
http://allenbrowne.com/ser-03.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"RICHARD BROMBERG" <no*****@att.net> wrote in message
news:YT********************@bgtnsc05-news.ops.worldnet.att.net...
I have a table (tblPhone) with text fields FULL, LAST, PHONE,

I also have a combo box (cmboFull) .
The row source for cmboFull is SELECT DISTINCT [FULL] FROM tblPhone;

Here's the code for the combo box

Private Sub cmboFull_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Full] = '" & Me![cmboFull] & "'"
Me.Bookmark = rs.Bookmark
This combo box populates ok but when I click on any item in the combo box I
get the following error on the "Set rs = Me.Recordset.Clone" statement.
Run time error '91'
Object variable or Withblock variable not set.

I used similar code in another program and it worked fine so I am puzzled why it fails here.

Any ideas

The overall objective is to present a combo box containing the data in the FULL field and
then set a couple of text boxes with the LAST and FULL fields in the
selected record.


Jun 5 '06 #3

P: n/a
Is this a bound form, i.e. does it have something in its RecordSource
property?

If the source is an Access table (or a query or SQL statement that uses
Access tables), you may need to change the declaration of:
Dim rs As Object
to:
Dim rs As DAO.Recordset
and make sure you have a reference to the DAO library. The reference is
present in all versions of Access except 2000 and 2002, so if you are stuck
on one of those versions, see:
http://allenbrowne.com/ser-38.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"RICHARD BROMBERG" <no*****@att.net> wrote in message
news:kO*********************@bgtnsc04-news.ops.worldnet.att.net...
Allen

I changed the code, removing the 2nd dot as you suggested, but that
generated the following error:
"You entered an expression that has an invalid reference to the
RecordsetClone property"

What else could be causing it.
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:44***********************@per-qv1-newsreader-01.iinet.net.au...
Try without the 2nd dot, i.e.:
Set rs = Me.RecordsetClone

There are several other things that could go wrong with that code,

including
reference priorities, the need to test NoMatch, and weird messages if the
record cannot be saved to activate the move (e.g. "Cannot Update without
Edit first".) For an example of a FindFirst that takes care of these

issues,
see:
http://allenbrowne.com/ser-03.html

"RICHARD BROMBERG" <no*****@att.net> wrote in message
news:YT********************@bgtnsc05-news.ops.worldnet.att.net...
>I have a table (tblPhone) with text fields FULL, LAST, PHONE,
>
> I also have a combo box (cmboFull) .
> The row source for cmboFull is SELECT DISTINCT [FULL] FROM tblPhone;
>
> Here's the code for the combo box
>
> Private Sub cmboFull_AfterUpdate()
> ' Find the record that matches the control.
> Dim rs As Object
> Set rs = Me.Recordset.Clone
> rs.FindFirst "[Full] = '" & Me![cmboFull] & "'"
> Me.Bookmark = rs.Bookmark
>
>
> This combo box populates ok but when I click on any item in the combo box > I
> get the following error on the "Set rs = Me.Recordset.Clone" statement.
> Run time error '91'
> Object variable or Withblock variable not set.
>
> I used similar code in another program and it worked fine so I am puzzled > why it fails here.
>
> Any ideas
>
> The overall objective is to present a combo box containing the data in the > FULL field and
> then set a couple of text boxes with the LAST and FULL fields in the
> selected record.

Jun 5 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.