ChristinaFC
IS-IT--Management
I have a number of comboboxes in my forms linking to a table with ~40.000 records. As this tends to make the loading of the forms rather slow I tried Allen Brownes approach where the rowsource only loads after the first three letters have been typed into the box, but cannot get it to work. I must admit I do not understand his code to 100%, so it might be that something has gone wrong in my adaptation.
Unfortunately I was not up to speed with naming conventions when creating the database, but hopefully it is still understandable.
Allen Browne's original code can be found at
The combobox has the following properties
name - cboFöretagsnamn
Controlsource - OrgnrID
Rowsource - blank
Rowsource Type - blank
Bound Column - 1
Column Count - 1
The Form which conatains the combobox is called frmÖversiktAvProjekt and has Recordset Type - Dynaset
The table Företag contains the fields OrgnrPID and Företagsnamn
When running the form, I see the values for the existing records in the combobox, but when adding new records, after having typed three figures the drop downbox still remain blank. What am I doing wrong?
The code:
Option Compare Database
Option Explicit
'Makes company name load to combobox when three letters are typed into the box
Dim strFtgsnamnStub As String
Const conFtgsnamnMin = 3
Function ReloadcboFöretagsnamnInfo(OrgnrID As String)
Dim strNewStub As String ' First chars of OrgnrID
'You can use the Nz function to return zero, a zero-length string (" "), or another specified value when a Variant is Null. expression.Nz(Value, ValueIfNull)
strNewStub = Nz(Left(OrgnrID, conFtgsnamnMin), "")
' If first n chars are the same as previously, do nothing.
If strNewStub <> strFtgsnamnStub Then
If Len(strNewStub) < conFtgsnamnMin Then
'Remove the RowSource
Me.cboFöretagsnamn.RowSource = "SELECT OrgnrPID FROM Företag WHERE (false) ;"
strFtgsnamnStub = ""
Else
'New RowSource
Me.cboFöretagsnamn.RowSource = "SELECT OrgnrPID FROM Företag WHERE (OrgnrPID Like """ & _
strNewStub & "*"");"
strFtgsnamnStub = strNewStub
End If
End If
End Function
Private Sub cboFöretagsnamn_Change()
Call ReloadcboFöretagsnamnInfo(Nz(Me.cboFöretagsnamn, ""))
End Sub
Private Sub frmÖversiktAvProjekt_Current()
Call ReloadcboFöretagsnamnInfo(Nz(Me.cboFöretagsnamn, ""))
End Sub
Unfortunately I was not up to speed with naming conventions when creating the database, but hopefully it is still understandable.
Allen Browne's original code can be found at
The combobox has the following properties
name - cboFöretagsnamn
Controlsource - OrgnrID
Rowsource - blank
Rowsource Type - blank
Bound Column - 1
Column Count - 1
The Form which conatains the combobox is called frmÖversiktAvProjekt and has Recordset Type - Dynaset
The table Företag contains the fields OrgnrPID and Företagsnamn
When running the form, I see the values for the existing records in the combobox, but when adding new records, after having typed three figures the drop downbox still remain blank. What am I doing wrong?
The code:
Option Compare Database
Option Explicit
'Makes company name load to combobox when three letters are typed into the box
Dim strFtgsnamnStub As String
Const conFtgsnamnMin = 3
Function ReloadcboFöretagsnamnInfo(OrgnrID As String)
Dim strNewStub As String ' First chars of OrgnrID
'You can use the Nz function to return zero, a zero-length string (" "), or another specified value when a Variant is Null. expression.Nz(Value, ValueIfNull)
strNewStub = Nz(Left(OrgnrID, conFtgsnamnMin), "")
' If first n chars are the same as previously, do nothing.
If strNewStub <> strFtgsnamnStub Then
If Len(strNewStub) < conFtgsnamnMin Then
'Remove the RowSource
Me.cboFöretagsnamn.RowSource = "SELECT OrgnrPID FROM Företag WHERE (false) ;"
strFtgsnamnStub = ""
Else
'New RowSource
Me.cboFöretagsnamn.RowSource = "SELECT OrgnrPID FROM Företag WHERE (OrgnrPID Like """ & _
strNewStub & "*"");"
strFtgsnamnStub = strNewStub
End If
End If
End Function
Private Sub cboFöretagsnamn_Change()
Call ReloadcboFöretagsnamnInfo(Nz(Me.cboFöretagsnamn, ""))
End Sub
Private Sub frmÖversiktAvProjekt_Current()
Call ReloadcboFöretagsnamnInfo(Nz(Me.cboFöretagsnamn, ""))
End Sub