Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Synchronising Form to the value in the combobox 1

Status
Not open for further replies.

thembela

Technical User
Jun 4, 2005
29
ZA
I have a form with a combo box on it. I’m trying to synchronise the form to the value in the combo box. Here’s my code attached to the Apply Filter Action of the Macro.

[Broker Number] = [Forms]![frmBroker]![CboFind]

[Broker number] is the name of the field in the underlying table and [CboFind] is the name of the field on the form and it contains the value I want to match. What could be wrong.
 
Hi

First a few sources of information

See the code generated by the combo box wizard

or

See FAQ in this forum, Combo Boxes, Combo Box as a navigation toll

You do not say which version of Access, or if you are using ADO or DAO, but basically you need code like so

Dim rs as Recordset
Set Rs = ME.Recordsetclone
rs.findfirst "[Broker Number] = " & [Forms]![frmBroker]![CboFind]
If rs.nomatch then
' code here for error message or whatever
else
me.bookmark = rs.bookmark
end if
set rs = nothing

Not if [Broker Number] is a string you need

rs.findfirst "[Broker Number] = '" & [Forms]![frmBroker]![CboFind] & "' "



Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thanks KenReay, you are an absolute satr .it worked.
 
KenReay, there's something baffling me here.Why is it that the ApplyFilterAction on the macro couldn't work.I attached the macro to the After_update event of the ComboBox.

Here's my macro to find a Record using the ApplyFilter Section:

Action Action Arguments
ApplFilter Where Condition:
[Broker Number]=[Forms]![frmBroker]![CboFind]

I'm using Access 2003
 
KenReay, everything seems to work perectly.Now the problem is when i enter the value that is not in the list .I want an error message to display that the value entered isn't in the list.And on top of that whatever value that was entered( not in the list must be deleted( reset to null) here's a piece of my code:

Private Sub Benton_AfterUpdate()
Dim rs As Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[BRK_ENTITY_NO] = " & [Forms]![frmBroker]![Benton]
If (DCount("*", "[Broker Information]", "[BRK_ENTITY_NO] = [forms]![frmBroker]![Benton]") = 0) Then
MsgBox " OOPS!!!THE VALUE ENTERED," & [Benton] & " IS NOT A VALID BROKER NUMBER"

Else
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing

End Sub
 
hi

why didn't you use:

If rs.nomatch then

as I suggested, you are doing two lookups, not very efficient

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top