mainform control AfterUpdate problem?

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

Guest

I have a mainform that has a combo box control: Combo65. There is a multi
tab subform that reflects the records that are linked to what is selected in
Combo65. I previously had a control that enabled users to "scroll" through
the available "ProjectName" field's records with Previous Record and Next
Record command buttons. That worked successfully, but as the ProjectName
records became abundant, I decided to change it to a drop-down list to make
that process faster/easier.

The AfterUpdate event for Combo65 is as follows:
Private Sub Combo65_AfterUpdate()
Me.RecordsetClone.FindFirst "ProjectName = '" & Combo65 & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub

Now when a ProjectName is selected from the drop-down, I get the following
error:
Run-time error '3077':
Syntax error (missing operator) in expression.

When I Debug, it highlights the second line: MeRecordsetClone.FindFirst....

Not being a VB expert, I am unable to identify why this doesn't work. Can
anyone help? Any feedback is greatly appreciated!
 
Kevin said:
I have a mainform that has a combo box control: Combo65. There is a multi
tab subform that reflects the records that are linked to what is selected in
Combo65. I previously had a control that enabled users to "scroll" through
the available "ProjectName" field's records with Previous Record and Next
Record command buttons. That worked successfully, but as the ProjectName
records became abundant, I decided to change it to a drop-down list to make
that process faster/easier.

The AfterUpdate event for Combo65 is as follows:
Private Sub Combo65_AfterUpdate()
Me.RecordsetClone.FindFirst "ProjectName = '" & Combo65 & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub

Now when a ProjectName is selected from the drop-down, I get the following
error:
Run-time error '3077':
Syntax error (missing operator) in expression.


I think you would get that error if the combo box's value is
a name like Bob's Barber Shop. This particular issue can be
avoided by using the Replace function to double up the ' in
the name.

But, I thought the record you want to find are in the
subform. Your code is searching for the record in the main
form. If that's the case, You want something more like:

With Me.subform.Form.RecordsetClone
.FindFirst "ProjectName = '" & Replace(Combo65, "'","''")
& "'"
Me.subform.Form.Bookmark = .Bookmark
End With
 
Does the code you suggested still belong in the AfterUpdate event? I tried
it bit now get a series of different errors.

Just to clarify, the record in the main form is a name such as Bob's Barber
Shop. But why the error now? The AfterUpdate event could be the same
regardless of how the control functions shouldn't it?... since it fires after
a selection is made.

I also don't necessarily want to "find" a record in the subform as you
responded. I just want the records to relate to the mainform.

My initial error led me to believe I was missing an operator, so I was
thinking that code was very close to being right. Again...any feedback is
appreciated!
Kevin
 
Sheesh Kevin, "a series of different errors" is much of a
clue. Did you use the name of your subform control where I
use the generic term "subform"?

Regardless, if you want the subform to be filtered to just
the records that match the combo box, then you do not need
any code in the AfterUpdate event. Instead, try setting the
subform control's Link Master/Child properties to the
ProjectName field.
 
Back
Top