473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Setting the size of column widths of a combo box through Code and Searching Combo Box

I have a combo box on a form which is based on table tblMachine. On that
combo box I have four columns visible MachineNumber, description, location
and type. The bound column is the MachineNumber and this is not set to 0 as
the machines have its number on which means the user should know the machine
number. My problem is if the user doesn't know the number. I have a button
which changes the row source of the combo box to order by description, but
when the user starts to type the description the relevant record does not
come up as machine number is still visible. Is it possible, when I change
the row source to also make the first column width 0 through code?

I also want to enable the user to search the combo box leaving the drop down
filled with the search results.
I also have an unbound textbox for the user to enter their search terms, but
I am not sure of the next step

Thanks in advance

Will

Nov 13 '05 #1
1 6112
I did a similar sort of thing with 4 options.

Code is here. mnake of it what you will.

Incidently I would strongly recomend using a MachineID (Autonumber) as the
key to your table rather than the MachineNumber

I know its a pigs ear, but the bound column is always the last one, and the
titles and column widths change according to the selection option
TypeOfSearch selected

Function NewTypeOfSearch() ' Changes the search box

Dim SQLStg As String, SQLStg1 As String

On Error GoTo NewSearch_Type_Err

With CodeContextObject
!BySearchType.RowSource = ""
!BySearchType.ColumnCount = 5
!SearchBox.RowSource = ""
!SearchBox.ColumnCount = 5

If !TypeOfSearch.Value = 1 Then ' My reference
!SearchText.Caption = "Select My Reference to Search For "
!BySearchType.ColumnWidths = "1000;2200;1600;2400;1800" 'In
Twips
!BySearchType.BoundColumn = 1
!SearchBox.ColumnWidths = "1000;2200;1600;2400;1800"
!SearchBox.BoundColumn = 1
If .Name = "Insured" Then
SQLStg = "SELECT Insured.InsuredID, [ILastName] & ' ' &
[IFirstName] AS Name, "
SQLStg = SQLStg + "RegistrationNos.RegistrationNo ,
Principals.PrincipalName, "
SQLStg = SQLStg + "Insured.PrincipalsRef, "
SQLStg = SQLStg + " Insured.Active "
SQLStg = SQLStg + "FROM RegistrationNos INNER JOIN "
SQLStg = SQLStg + "(Principals INNER JOIN Insured "
SQLStg = SQLStg + "ON Principals.PrincipalID =
Insured.PrincipalID) "
SQLStg = SQLStg + "ON RegistrationNos.RegistrationNoID =
Insured.RegistrationNoID "
SQLStg1 = SQLStg ' Save the SQL
SQLStg = SQLStg + "WHERE Insured.InsuredID Like " & Chr$(34) &
!Filter & Chr$(34)
If !Activity < 1 Then
SQLStg = SQLStg + " AND Insured.Active = " & !Activity & " "
SQLStg1 = SQLStg1 + " WHERE Insured.Active = " & !Activity &
" "
End If
SQLStg = SQLStg + "ORDER BY Insured.InsuredID;"
SQLStg1 = SQLStg1 + "ORDER BY Insured.InsuredID;"
Else ' ArcInsured form
SQLStg = "SELECT ArcInsured.InsuredID, [ILastName] & ' ' &
[IFirstName] AS Name, "
SQLStg = SQLStg + "RegistrationNos.RegistrationNo ,
Principals.PrincipalName, "
SQLStg = SQLStg + "ArcInsured.PrincipalsRef "
SQLStg = SQLStg + "FROM RegistrationNos INNER JOIN "
SQLStg = SQLStg + "(Principals INNER JOIN ArcInsured "
SQLStg = SQLStg + "ON Principals.PrincipalID =
ArcInsured.PrincipalID) "
SQLStg = SQLStg + "ON RegistrationNos.RegistrationNoID =
ArcInsured.RegistrationNoID "
SQLStg1 = SQLStg ' Save the SQL
SQLStg = SQLStg + "WHERE ArcInsured.InsuredID Like " & Chr$(34)
& !Filter & Chr$(34)
SQLStg = SQLStg + " ORDER BY ArcInsured.InsuredID;"
SQLStg1 = SQLStg1 + " ORDER BY ArcInsured.InsuredID;"
End If
ElseIf !TypeOfSearch.Value = 2 Then ' Principals reference
!SearchText.Caption = "Select the Principals Reference to Search For
"
!BySearchType.ColumnWidths = "1800;2400;2200;1600;1000"
!BySearchType.BoundColumn = 5
!SearchBox.ColumnWidths = "1800;2400;2200;1600;1000"
!SearchBox.BoundColumn = 5
If .Name = "Insured" Then
SQLStg = "SELECT Insured.PrincipalsRef,
Principals.PrincipalName, "
SQLStg = SQLStg + "[ILastName] & ' ' & Insured.IFirstName AS
Name, "
SQLStg = SQLStg + "RegistrationNos.RegistrationNo,
Insured.InsuredID, "
SQLStg = SQLStg + " Insured.Active "
SQLStg = SQLStg + "FROM RegistrationNos INNER JOIN "
SQLStg = SQLStg + "(Principals INNER JOIN Insured "
SQLStg = SQLStg + "ON Principals.PrincipalID =
Insured.PrincipalID) "
SQLStg = SQLStg + "ON RegistrationNos.RegistrationNoID =
Insured.RegistrationNoID "
SQLStg1 = SQLStg ' Save the SQL
SQLStg = SQLStg + "WHERE Insured.PrincipalsRef Like " & Chr$(34)
& !Filter & Chr$(34)
If !Activity < 1 Then
SQLStg = SQLStg + " AND Insured.Active = " & !Activity & " "
SQLStg1 = SQLStg1 + " WHERE Insured.Active = " & !Activity &
" "
End If
SQLStg = SQLStg + "ORDER BY Principals.PrincipalName,
Insured.PrincipalsRef;"
SQLStg1 = SQLStg1 + "ORDER BY Principals.PrincipalName,
Insured.PrincipalsRef;"
Else ' ArcInsured form
SQLStg = "SELECT ArcInsured.PrincipalsRef,
Principals.PrincipalName, "
SQLStg = SQLStg + "[ILastName] & ' ' & ArcInsured.IFirstName AS
Name, "
SQLStg = SQLStg + "RegistrationNos.RegistrationNo,
ArcInsured.InsuredID "
SQLStg = SQLStg + "FROM RegistrationNos INNER JOIN "
SQLStg = SQLStg + "(Principals INNER JOIN ArcInsured "
SQLStg = SQLStg + "ON Principals.PrincipalID =
ArcInsured.PrincipalID) "
SQLStg = SQLStg + "ON RegistrationNos.RegistrationNoID =
ArcInsured.RegistrationNoID "
SQLStg1 = SQLStg ' Save the SQL
SQLStg = SQLStg + "WHERE ArcInsured.PrincipalsRef Like " &
Chr$(34) & !Filter & Chr$(34)
SQLStg = SQLStg + " ORDER BY Principals.PrincipalName,
ArcInsured.PrincipalsRef;"
SQLStg1 = SQLStg1 + " ORDER BY Principals.PrincipalName,
ArcInsured.PrincipalsRef;"
End If
ElseIf !TypeOfSearch.Value = 3 Then ' Insured name
!SearchText.Caption = "Select the Insured Name to Search For"
!BySearchType.ColumnWidths = "2200;1600;2400;1800;1000"
!BySearchType.BoundColumn = 5
!SearchBox.ColumnWidths = "2200;1600;2400;1800;1000"
!SearchBox.BoundColumn = 5
If .Name = "Insured" Then
SQLStg = "SELECT Insured.ILastName & ' ' & Insured.IFirstName AS
Name, "
SQLStg = SQLStg + "RegistrationNos.RegistrationNo, "
SQLStg = SQLStg + "Principals.PrincipalName,
Insured.PrincipalsRef, "
SQLStg = SQLStg + "Insured.InsuredID, Insured.Active "
SQLStg = SQLStg + "FROM RegistrationNos INNER JOIN "
SQLStg = SQLStg + "(Principals INNER JOIN Insured "
SQLStg = SQLStg + "ON Principals.PrincipalID =
Insured.PrincipalID) "
SQLStg = SQLStg + "ON RegistrationNos.RegistrationNoID =
Insured.RegistrationNoID "
SQLStg1 = SQLStg ' Save the SQL
SQLStg = SQLStg + "WHERE Insured.ILastName Like " & Chr$(34) &
!Filter & Chr$(34)
If !Activity < 1 Then
SQLStg = SQLStg + " AND Insured.Active = " & !Activity & " "
SQLStg1 = SQLStg1 + " WHERE Insured.Active = " & !Activity &
" "
End If
SQLStg = SQLStg + "ORDER BY Insured.ILastName,
Insured.IFirstName;"
SQLStg1 = SQLStg1 + "ORDER BY Insured.ILastName,
Insured.IFirstName;"
Else
SQLStg = "SELECT ArcInsured.ILastName & ' ' &
ArcInsured.IFirstName AS Name, "
SQLStg = SQLStg + "RegistrationNos.RegistrationNo, "
SQLStg = SQLStg + "Principals.PrincipalName,
ArcInsured.PrincipalsRef, "
SQLStg = SQLStg + "ArcInsured.InsuredID "
SQLStg = SQLStg + "FROM RegistrationNos INNER JOIN "
SQLStg = SQLStg + "(Principals INNER JOIN ArcInsured "
SQLStg = SQLStg + "ON Principals.PrincipalID =
ArcInsured.PrincipalID) "
SQLStg = SQLStg + "ON RegistrationNos.RegistrationNoID =
ArcInsured.RegistrationNoID "
SQLStg1 = SQLStg ' Save the SQL
SQLStg = SQLStg + "WHERE ArcInsured.ILastName Like " & Chr$(34)
& !Filter & Chr$(34)
SQLStg = SQLStg + " ORDER BY ArcInsured.ILastName,
ArcInsured.IFirstName;"
SQLStg1 = SQLStg1 + " ORDER BY ArcInsured.ILastName,
ArcInsured.IFirstName;"
End If
ElseIf !TypeOfSearch.Value = 4 Then ' Vehicle Number
!SearchText.Caption = "Select the Insured Name to Search For
"
!BySearchType.ColumnWidths = "1600;2200;1800;2400;1000"
!BySearchType.BoundColumn = 5
!SearchBox.ColumnWidths = "1600;2200;1800;2400;1000"
!SearchBox.BoundColumn = 5
If .Name = "Insured" Then
SQLStg = "SELECT RegistrationNos.RegistrationNo, "
SQLStg = SQLStg + "Insured.ILastName & ' ' & Insured.IFirstName
AS Name, "
SQLStg = SQLStg + "Insured.PrincipalsRef,
Principals.PrincipalName, "
SQLStg = SQLStg + "Insured.InsuredID, Insured.Active "
SQLStg = SQLStg + "FROM RegistrationNos INNER JOIN "
SQLStg = SQLStg + "(Principals INNER JOIN Insured "
SQLStg = SQLStg + "ON Principals.PrincipalID =
Insured.PrincipalID) "
SQLStg = SQLStg + "ON RegistrationNos.RegistrationNoID =
Insured.RegistrationNoID "
SQLStg1 = SQLStg ' Save the SQL
SQLStg = SQLStg + "WHERE RegistrationNos.RegistrationNO Like " &
Chr$(34) & !Filter & Chr$(34)
If !Activity < 1 Then
SQLStg = SQLStg + " AND Insured.Active = " & !Activity & " "
SQLStg1 = SQLStg1 + " WHERE Insured.Active = " & !Activity &
" "
End If
SQLStg = SQLStg + "ORDER BY RegistrationNos.RegistrationNo;"
SQLStg1 = SQLStg1 + "ORDER BY RegistrationNos.RegistrationNo;"
Else ' ArcInsured
SQLStg = "SELECT RegistrationNos.RegistrationNo, "
SQLStg = SQLStg + "ArcInsured.ILastName & ' ' &
ArcInsured.IFirstName AS Name, "
SQLStg = SQLStg + "ArcInsured.PrincipalsRef,
Principals.PrincipalName, "
SQLStg = SQLStg + "ArcInsured.InsuredID "
SQLStg = SQLStg + "FROM RegistrationNos INNER JOIN "
SQLStg = SQLStg + "(Principals INNER JOIN ArcInsured "
SQLStg = SQLStg + "ON Principals.PrincipalID =
ArcInsured.PrincipalID) "
SQLStg = SQLStg + "ON RegistrationNos.RegistrationNoID =
ArcInsured.RegistrationNoID "
SQLStg1 = SQLStg ' Save the SQL
SQLStg = SQLStg + "WHERE RegistrationNos.RegistrationNo Like " &
Chr$(34) & !Filter & Chr$(34)
SQLStg = SQLStg + " ORDER BY RegistrationNos.RegistrationNo;"
SQLStg1 = SQLStg1 + " ORDER BY RegistrationNos.RegistrationNo;"
End If
End If
!BySearchType.RowSource = SQLStg
!SearchBox.RowSource = SQLStg1
End With
Exit Function

NewSearch_Type_Err:
MsgBox "Error is " & Error$, 16
Exit Function

End Function
"Will" <Wi********@hotmail.com> wrote in message
news:36*************@individual.net...
I have a combo box on a form which is based on table tblMachine. On that
combo box I have four columns visible MachineNumber, description, location
and type. The bound column is the MachineNumber and this is not set to 0
as
the machines have its number on which means the user should know the
machine
number. My problem is if the user doesn't know the number. I have a
button
which changes the row source of the combo box to order by description, but
when the user starts to type the description the relevant record does not
come up as machine number is still visible. Is it possible, when I change
the row source to also make the first column width 0 through code?

I also want to enable the user to search the combo box leaving the drop
down
filled with the search results.
I also have an unbound textbox for the user to enter their search terms,
but
I am not sure of the next step

Thanks in advance

Will

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: cpt | last post by:
I read that if one uses "table-layout:fixed" then table rendering is speeded by setting row height. All my rows are 285 px high. 1) Is this true? 2) If true, how does one set row-height for the...
2
by: Todd | last post by:
Hello, I'm curious if anyone knows of a way (if one exists) to tell a form (in Access 2002 VBA) to sort on an unbound column of a combo box on the form. Here's what I want to do: A combo box...
2
by: Ed via AccessMonster.com | last post by:
Hi all, What I am trying to do is get the value of the second column of a bound combo box in vba. example: Combo box: column 1-ID column 2-SIGN_CODE 1 R-1.gif 2 ...
5
by: nimdez | last post by:
Hi, I am working on an existing code base in which a lot of data displayed to the user is formatted in tables. Most tables are printed row-by-row using printf() with "%s" print conversion...
12
by: J L | last post by:
When I fill a listview, I resize the columns to fit the data. I need to know if the data will fit vertically or if there will be a vertical scroll bar. I need to know this so I can allow for it on...
5
by: Steve Bugden | last post by:
Hi, I would like to set the column widths in the ASP.NET GridView control at runtime I have tried the following: http://msdn2.microsoft.com/en-us/library/ms178296.aspx Which uses the...
2
by: saxm-un | last post by:
Hi, I'm just beginning CSS based web development and although I've been bashing away at it since yesterday, I'm still stuck with positioning things on pages. I'm trying to make (in table-speak)...
4
by: Chuck | last post by:
I'm setting the column with for a gridview (25+- columns) and have paging turned on. When the gridview is first displayed, the column widths are all set to the default. But after paging to...
3
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I am wondering what is considered a best practice for setting column widths to fit the data for a DataGridView (.Net 2.0) that was created on-the-fly from an arbitrary query. What I would probably...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.