Find the record that matches the control.

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

Guest

Hi. I have this code in a combobox to find a record. This is automatically
generated from Access. It really works good. My problem is that my form that
has this combobox control is in a form that is a sub-form.

So when I open the form as mais form works ok, but if I open the form as a
sub-form it doesn't work.

What do I have to change in this code to make it work when is open has a
sub-form?

Private Sub Combo35_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ID_Detalhes_Areas_Vistorias] = " & Str(Nz(Me![Combo35], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub


Regards,
Marco
 
You need to make reference to the subforms recordset and recordsetclone
properties.

Something like the following should work assuming your subForm Control is
called frmSubFormName andAssuming I have made no typos.

Private Sub Combo35_AfterUpdate()
ON error GoTo Err_Label
Dim strSearch as string
strSearch = "[ID_Detalhes_Areas_Vistorias] = " & nz(me.combo35,0)
Me.frmSubFormName.Form.Recordsetclone.FindFirst strSearch
IF Me.frmSubFormName.Form.Recordsetclone.NoMatch then
' item not found - pop up an informational message to the user
Msgbox "That item not found", vbOkOnly, "Item Not Found"
Me.frmSubFormName.Form.Recordsetclone.Bookmark =
Me.frmSubFormName.Form.Bookmark
ELSE
' Set the bookmark of the subform recordset to the same as the
recordsetclone
Me.subFormName.Form.BookMark =
me.frmSubFormName.Form.Recordsetclone.Bookmark
End If
Exit_Label:
Exit sub
Err_Label:
Msgbox err.number & vbcrlf & err.description
Resume Exit_Label
End Sub

You could use a :
With Me.frmSubFormName.Form.Recordsetclone
' Blah, blah, blah
End With

to cut down on typing and improve performance.
 
Hi. The form will be open as subform. Sorry I didn't mention that before.

Regards,
Marco

B. Edwards said:
You need to make reference to the subforms recordset and recordsetclone
properties.

Something like the following should work assuming your subForm Control is
called frmSubFormName andAssuming I have made no typos.

Private Sub Combo35_AfterUpdate()
ON error GoTo Err_Label
Dim strSearch as string
strSearch = "[ID_Detalhes_Areas_Vistorias] = " & nz(me.combo35,0)
Me.frmSubFormName.Form.Recordsetclone.FindFirst strSearch
IF Me.frmSubFormName.Form.Recordsetclone.NoMatch then
' item not found - pop up an informational message to the user
Msgbox "That item not found", vbOkOnly, "Item Not Found"
Me.frmSubFormName.Form.Recordsetclone.Bookmark =
Me.frmSubFormName.Form.Bookmark
ELSE
' Set the bookmark of the subform recordset to the same as the
recordsetclone
Me.subFormName.Form.BookMark =
me.frmSubFormName.Form.Recordsetclone.Bookmark
End If
Exit_Label:
Exit sub
Err_Label:
Msgbox err.number & vbcrlf & err.description
Resume Exit_Label
End Sub

You could use a :
With Me.frmSubFormName.Form.Recordsetclone
' Blah, blah, blah
End With

to cut down on typing and improve performance.

Marco said:
Hi. I have this code in a combobox to find a record. This is automatically
generated from Access. It really works good. My problem is that my form
that
has this combobox control is in a form that is a sub-form.

So when I open the form as mais form works ok, but if I open the form as a
sub-form it doesn't work.

What do I have to change in this code to make it work when is open has a
sub-form?

Private Sub Combo35_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ID_Detalhes_Areas_Vistorias] = " & Str(Nz(Me![Combo35],
0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub


Regards,
Marco
 
Is returning an error here:
Me.[38_form_Vistorias_Areas_Detalhes].Form.RecordsetClone.FindFirst strSearch

Why?


MArco



B. Edwards said:
You need to make reference to the subforms recordset and recordsetclone
properties.

Something like the following should work assuming your subForm Control is
called frmSubFormName andAssuming I have made no typos.

Private Sub Combo35_AfterUpdate()
ON error GoTo Err_Label
Dim strSearch as string
strSearch = "[ID_Detalhes_Areas_Vistorias] = " & nz(me.combo35,0)
Me.frmSubFormName.Form.Recordsetclone.FindFirst strSearch
IF Me.frmSubFormName.Form.Recordsetclone.NoMatch then
' item not found - pop up an informational message to the user
Msgbox "That item not found", vbOkOnly, "Item Not Found"
Me.frmSubFormName.Form.Recordsetclone.Bookmark =
Me.frmSubFormName.Form.Bookmark
ELSE
' Set the bookmark of the subform recordset to the same as the
recordsetclone
Me.subFormName.Form.BookMark =
me.frmSubFormName.Form.Recordsetclone.Bookmark
End If
Exit_Label:
Exit sub
Err_Label:
Msgbox err.number & vbcrlf & err.description
Resume Exit_Label
End Sub

You could use a :
With Me.frmSubFormName.Form.Recordsetclone
' Blah, blah, blah
End With

to cut down on typing and improve performance.

Marco said:
Hi. I have this code in a combobox to find a record. This is automatically
generated from Access. It really works good. My problem is that my form
that
has this combobox control is in a form that is a sub-form.

So when I open the form as mais form works ok, but if I open the form as a
sub-form it doesn't work.

What do I have to change in this code to make it work when is open has a
sub-form?

Private Sub Combo35_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ID_Detalhes_Areas_Vistorias] = " & Str(Nz(Me![Combo35],
0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub


Regards,
Marco
 

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

Back
Top