Question : Access VB for combo box

I am trying to use Allen Browne's excellnt tips for how to speed up a form with combobox looking up values in tables with a vast number of records (http://allenbrowne.com/ser-32.html)I

I have a form with a combobox (cboFöretagsnamn). In the form I want to show the name of a company (Företagsnamn), but the bound column should be a numerical value (the primary key in the table with company names: OrgnrPID.
This works when I write the following text in the RowSource Property of the combobox:
SELECT [företag]![Företagsnamn] & " - " & [Företag]![OrgnrPID] AS Expr, Företag.OrgnrPID FROM Företag ORDER BY [företag]![Företagsnamn] & " - " & [Företag]![OrgnrPID];

However, when I try Allen's solution in order to speed up the form, nothing at all shows up in the combobox in the form for existing records, and when I add new records, the typeahead does not work either.

Does anyone know what I am doing wrong (I am quite a newbie at VBA)?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
Option Compare Database
Option Explicit
 
'Makes company name load to combobox when three letters are typed into the box
 
Dim sFtgsnamnStub As String
Const conFtgsnamnMin = 3
Function ReloadcboFöretagsnamnInfo(sFtgsnamn As String)
    Dim sNewStub As String    ' First chars of cboFöretagsnamn.Text
    sNewStub = Nz(Left(sFtgsnamn, conFtgsnamnMin), "")
    ' If first n chars are the same as previously, do nothing.
    If sNewStub <> sFtgsnamnStub Then
        If Len(sNewStub) < conFtgsnamnMin Then
            'Remove the RowSource
            Me.cboFöretagsnamn.RowSource = "SELECT Företagsnamn, OrgnrPID FROM Företag WHERE (false) ;"
            sFtgsnamnStub = ""
        Else
            'New RowSource
            Me.cboFöretagsnamn.RowSource = "SELECT Företagsnamn, OrgnrPID FROM Företag WHERE (Företagsnamn Like """ & sNewStub & "*"") ORDER BY Företagsnamn ;"
            sFtgsnamnStub = sNewStub
        End If
    End If
End Function
 
 
Private Sub cboFöretagsnamn_Change()
  Call ReloadcboFöretagsnamnInfo(Nz(Me.cboFöretagsnamn, ""))
End Sub
 
Private Sub cboFöretagsnamn_Current()
  Call ReloadcboFöretagsnamnInfo(Nz(Me.cboFöretagsnamn, ""))
End Sub

Answer : Access VB for combo box

The form current event should have this format:
   Private Sub Form_Current()
not this format:
Private Sub frmÖversiktAvProjekt_Current()

To make sure the current event is attached to the procedure do this. Select the form by clicking on the small square dot appearing in the upper, left corner of the form in design form (see image).  In the Event tab of the properties window select [Event Procedure] in the on current event drop down.  Click on the button with three dots to the right of the drop down arrow. this will open the visual basic editor with Private Sub Form_Current() showing. Move
  Call ReloadcboFöretagsnamnInfo(Nz(Me.cboFöretagsnamn, ""))
to there so it looks like this:
Private Sub Form_Current()
  Call ReloadcboFöretagsnamnInfo(Nz(Me.cboFöretagsnamn, ""))
End Sub
 
Select form
Select form
 
Random Solutions  
 
programming4us programming4us