Hi Crystal,
Okay...I'm 98% there. This is working almost perfect, and so simple. With
two combo boxes and using the visible attribute, only a few lines of code and
it works great. One more hopefully small issue and it's perfect. Since the PO
No's are unique, they work perfect. You select a PO No from the drop down
list and it's displayed on the form. Not quite so perfect with the Property
Name combo box. There are duplicate Property Names as any property can have
numerous PO's. When the drop down list appears, the Properties are sorted
alphabetically with the unique PO's displayed besides the names as should be.
The property names will be duplicated as again any property may have multiple
PO's. Lets say a property named Yorkdale Mall has 5 PO's. Therefore in the
dropdown list, it will show 5 lines of Yorkdale Mall, each with a unique PO
number beside it. So far so good. Let's say the first Yorkdale Mall entry has
PO number 1024. No matter which line for Yorkdale I click on, it always
selects the first PO 1024, the first in the list for Yorkdale. The same
happens fo all other properties, it always selects the first PO for that
particular property. Do you know a way I can fix this so it selects the
actual PO I click on? Let me know. Thanks again!
Howard
:
Hi Howard,
You're welcome
I would have been surprised if that code
WAS perfect as I didn't set up a form to test it, just
wanted to give you logic. I am glad you got it to work
Instead of changing one search combo, you may want to use
multiple combos (they don't have to be wide for the list to
be wide) -- this makes it very easy to add additional sort
options without changing combobox properties. Just set the
first column of each combo to the field with the primary key
and you can use the same code.
Is PO No the unique field in your record?
Warm Regards,
Crystal
MVP Microsoft Access
remote programming and training
strive4peace2006 at yahoo.com
*
Have an awesome day
hfreedman wrote:
Hi Crystal,
Thanks for the code. It didn't quite work out-of-the box. I modified is as
follows. Currently, the first time in, the serach by Property Name works. The
switching to Search By PO No, work as well. However, when I switch back to
Search By Property Name, the columns in the drop down are screwed up and it
always return the first record in the list regardless of which is picked. The
Search By PO No always worked when switched to. Please have a look at my code
and offer any advise. Thanks! - Howard
Private Sub cmdSwitchSearch_Click()
Dim strSQL As String, mCaption As String
strSQL = "SELECT [PO No], " _
& " [Property Name], " _
& " [Issue Date], " _
& " [Supplier Name] " _
& " FROM qryPurchaseOrder " _
& " ORDER BY "
If Me.cmdSwitchSearch.Caption _
= "Search By PO No." Then
mCaption = "Search By Property Name"
Me.SearchForPOLabel.Caption = "PO No. Search: "
Me.SearchForPO.ColumnWidths = "2"";.25"";2"";2"
strSQL = strSQL & " [PO No], [Property Name]"
Else
mCaption = "Search By PO No."
Me.SearchForPOLabel.Caption = "Property Search: "
Me.SearchForPO.ColumnWidths = ".25"";2"";2"";2"
strSQL = strSQL & " [Property Name], [PO No]"
End If
strSQL = strSQL & ",[Issue Date], [Supplier Name];"
Me.SearchForPO.RowSource = strSQL
Me.SearchForPO.Requery
Me.SearchForPO.SetFocus
Me.cmdSwitchSearch.Caption = mCaption
End Sub
Private Sub SearchForPO_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
If Me.cmdSwitchSearch.Caption = "Search By PO No." Then
rs.FindFirst "[Property Name] = '" & Me![SearchForPO] & "'"
Else
rs.FindFirst "[PO No] = " & Str(Nz(Me![SearchForPO], 0))
End If
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
:
Hello Howard,
OnClick event of the SwitchSearch Command Button:
'~~~~~~~~~~~~~~~~~~~~~~~~~~`
dim strSQL as string, mCaption as string
strSQL = "SELECT [PO No], " _
& " [Property Name], " _
& " [Issue Date], " _
& " [Supplier Name] " _
& " FROM qryPurchaseOrder " _
& " ORDER BY "
if me.cmdSwitchSearch.caption _
= "Search By PO No" then
mCaption = "Search By Property Name"
me.combobox_controlname.ColumnWidths = 1;2;1;2
strSQL = strSQL & " [PO No], [Property Name]"
else
mCaption = "Search By PO No"
me.combobox_controlname.ColumnWidths = 0;3;1;2
strSQL = strSQL & " [Property Name] "
end if
strSQL = strSQL & ",[Issue Date], [Supplier Name];"
me.combobox_controlname.RowSource = strSQL
me.combobox_controlname.Requery
me.combobox_controlname.SetFocus
me.cmdSwitchSearch.caption = mCaption
'you may need to uncomment this line
'DoEvents
'~~~~~~~~~~~~~~~~~~~~~~~~~~
where cmdSwitchSearch is the controlname of your Search
command button
AfterUpdate event of the combobox:
'~~~~~~~~~~~~~~~~~~~~~~~~~~
If IsNull(Me.ActiveControl) Then Exit Function
'save current record if changes were made
If me.dirty then me.dirty = false
Dim mPoNo as string
mPoNo = Me.ActiveControl
Me.ActiveControl = Null
Me.RecordsetClone.FindFirst "[Po No]= '" & mPoNo & "'"
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
Exit Sub
End If
'~~~~~~~~~~~~~~~~~~~~~~~~~~
I am assuming that Po Number will always be filled out.
Ideally, the first column in each combo would be the unique
recordID (autonumber/long integer data type).
Warm Regards,
Crystal
MVP Microsoft Access
remote programming and training
strive4peace2006 at yahoo.com
*
Have an awesome day
hfreedman wrote:
I'm sorry but I need to post my problem again. Thanks to Klatuu, I now
realize a simpler approach to resolve my issue but I still need help.
I have a form called frmPurchaseOrder which displays a single purchase order
record at a time using a query record source call qryPurchaseOrder. On the
form is a combo box called SearchForPO to search for and display a particular
purchase order record. The fields to display in the SearchForPO drop down
list are [PO No], [Property Name], [Issue Date]. and [Supplier Name]. I want
to be able to search two ways, by [Property Name] or by [PO No]. I have a
command button called SwitchSearch. If SearchForPO is currently set to search
by Property Name, when SwitchSearch is clicked, I want the following to
happen:
1) The SearchForPO ComboBox label will change from "PO No Search" to
"Property Name Search"
2) The SearchForPO ComboBox drop down list will display the records in [PO
No] order with the field order as [PO No], [Property Name], [Issue Date]. and
[Supplier Name]
3) The SwitchSearch Command Button Caption will change from "Search By PO
No" to "Search By Property Name"
If SearchForPO is currently set to search by PO No, when SwitchSearch is
clicked, I want the following to happen:
1) The SearchForPO ComboBox label will change from "Property Name Search" to
"PO No Search"
2) The SearchForPO ComboBox drop down list will display the records in
[Property Name] order with the field order as [Property Name], [PO No],
[Issue Date]. and [Supplier Name]
3) The SwitchSearch Command Button Caption will change from "Search By
Property Name" back to "Search By PO No"
I hope this is clear. I need examples of statements to accomplish this or
just the exact code
Any help will be appreciated. Thanks so much!
Howard