DarrenBoyer
IS-IT--Management
This is a straitforward request but I can't seem to find an answer anywhere.
I'm modifying code from Desktop Developers Handbook:
In the book's example it shows how to use command buttons to control how a list box is populated.
My situation is a little different in that I need to have a combo box populated instead of a list box.
The object of this design is to give the user's the ability to search for existing customers. However, I have some customer's who are Organization's and some who are Individual's and these are two different fields.
Right now the combo box is populated and once I select a record it nicely fills in the rest of my form. [red] However, I don't have the normal Findfirst functionality of a normal combobox.[/red] As in the records search as keys are pressed.
Next Function Works Nicely
Here is where I have problems
I'm modifying code from Desktop Developers Handbook:
In the book's example it shows how to use command buttons to control how a list box is populated.
My situation is a little different in that I need to have a combo box populated instead of a list box.
The object of this design is to give the user's the ability to search for existing customers. However, I have some customer's who are Organization's and some who are Individual's and these are two different fields.
Right now the combo box is populated and once I select a record it nicely fills in the rest of my form. [red] However, I don't have the normal Findfirst functionality of a normal combobox.[/red] As in the records search as keys are pressed.
Code:
Private Enum ShowType
ShowOrganization = 1
ShowIndividual = 2
End Enum
Public Sub cmdOrgSearch_Click()
SetcomContents ShowOrganization
End Sub
Public Sub cmdIndivSearch_Click()
SetcomContents ShowIndividual
End Sub
Next Function Works Nicely
Code:
Private Function SetcomContents(st As ShowType)
' Example function to show a method of filling lists using
' VBA.
Dim intID As String
Dim strField As String
Dim strTable As String
Dim strFill As String
Dim strSQL As String
txtSelected = Null
Select Case st
Case ShowOrganization
strField = "OrgName"
strTable = "Customers"
txtSelected.ControlTipText = "Selected Organization"
Case ShowIndividual
strField = "IndivLastName"
strTable = "Customers"
txtSelected.ControlTipText = "Selected Individual"
Case Else
Exit Function
End Select
' Build the appropriate SQL string.
strSQL = "SELECT DISTINCTROW [" & strField & "] FROM " _
& strTable & " WHERE [" & strField & "] Is Not Null ORDER BY [" & strField & "]"
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open _
Source:=strSQL, _
ActiveConnection:=CurrentProject.Connection, _
CursorType:=adOpenStatic, _
Options:=adCmdText
cmbCustSearch.RowSourceType = "Table/Query"
Set cmbCustSearch.Recordset = rst
' Don't explicitly close the recordset here.
' You want it to be open for the list box to use.
Set rst = Nothing
End Function
Here is where I have problems
Code:
Private Sub cmbCustSearch_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
Me.FindFirst "[cmbCustSearch] = '" & Me![cmbCustSearch] & "'"
txtSelected = cmbCustSearch
End Sub