Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing me. when moving code from form to module 1

Status
Not open for further replies.

ChristinaFC

IS-IT--Management
Jan 1, 2010
8
SE
I have a piece of code (a function) that is used in many of the forms in my Access 2007 db. The code contains me. -references, and as I have understood it, me. does not work in modules. Is there some other reference that can be used instead?

Example of the code:
'Makes company name and PersonID3 load to combobox when three letters are typed into the box
Sub ReloadcboPersonID3(strTextICbo As String)
Const conPerson2Min = 3
If Len(strTextICbo) > conPerson2Min Then GoTo LastLine
Dim strPersonNamnStub As String
Dim strNewStub As String ' First chars of texten i cbo
'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(strTextICbo, conPerson2Min), "")
' If first n chars are the same as previously, do nothing.
If strNewStub <> strPersonNamnStub Then
If Len(strNewStub) < conPerson2Min Then
'Remove the RowSource
Me.cboPersonID3.RowSource = ""
strPersonNamnStub = ""
Else
'New RowSource
Me.cboPersonID3.RowSource = "SELECT fldPersonExklFtg, PersonPID FROM qryPersonLista WHERE (fldPersonExklFtg Like """ & strNewStub & "*"")"
strPersonNamnStub = strNewStub
Me.cboPersonID3.Dropdown
End If
End If
LastLine:
End Sub
 
you could use activeform activecontrol but that is not good design. Just pass in to the function the actual combobox

Sub Reloadcbo(strTextICbo As String, cbo as access.combobox)
....
your code

cbo.rowsource = ....
end sub


so when you call it it probably looks like

call reloadcbo(me.comboname.value, me.comboname)
 
Super!

First when I tried it I got an error message "Run-time error '94': Invalid use of Null" and when I held the cursor over (me.Comboname.Value, me.Comboname) it displays "me.Comboname.Value=Null

I then changed "call reloadcbo(me.comboname.value, me.comboname" to "call reloadcbo(me.comboname.text, me.comboname)" and then it worked like a charm.

Many thanks!
 
probably better to pass it
nz(me.comboname.text,"")

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top