OrderBy Form Name Error

J

Joe Wroblewski

I've got a number of forms each of which have command buttons to sort
the forms.
They work just fine. As I add new similar forms I wanted to run the
repetitive code in standard subroutines in a module.
My problem is that I can't use:
Me!OrderBy = strOrderBy
in the standard module.
And when I try to supply the form name I get the following error message:
Run-time Error '2450'
[The Application] can't find the form ' strCurrentFormName'
referred to in a macro expression or Visual Basic code.
My code follows.

Help!
Thanks,
Joe W


MODULE
Public strSortCrit1, strSortCrit2 As String
Public strSortCrit3, strSortCrit4 As String
Public strOrderBy As String
Public strCurrentFormName As String
Public intLen As Integer

Public Sub PrepSort()
strOrderBy = ""
strSortCrit1 = ""
strSortCrit2 = ""
strSortCrit3 = ""
strSortCrit4 = ""
strCurrentFormName = Application.CurrentObjectName
MsgBox "A. strCurrentFormName: " & strCurrentFormName
End Sub

Public Sub RunSort()
strOrderBy = strSortCrit1 & strSortCrit2 & _
strSortCrit3 & strSortCrit4
intLen = Len(strOrderBy)
MsgBox "B. strCurrentFormName: " & strCurrentFormName
If intLen > 0 Then
Forms!strCurrentFormName!OrderBy = strOrderBy
Forms!strCurrentFormName!OrderByOn = True
Else
' Forms!strCurrentFormName!OrderByOn = False
End If
End Sub

' *************************************************************
FORM MODULE

Public Sub SortBySort_Click()
PrepSort
strSortCrit1 = "acSort1, "
strSortCrit2 = "acAssetClass, "
RunSort
End Sub
 
J

Joe Wroblewski

I repeated my question but trimmed out excess code:

I've got a number of forms each of which have command buttons to sort
the forms.
They work just fine. As I add new similar forms I wanted to run the
repetitive code in standard subroutines in a module.
My problem is that I can't use:
Me!OrderBy = strOrderBy
in the standard module.
And when I try to supply the form name I get the following error message:
Run-time Error '2450'
[The Application] can't find the form ' strCurrentFormName'
referred to in a macro expression or Visual Basic code.
My code follows.

Help!
Thanks,
Joe W


MODULE
Public strSortCrit1, strSortCrit2 As String
Public strOrderBy As String
Public strCurrentFormName As String
Public intLen As Integer

Public Sub PrepSort()
strOrderBy = ""
strSortCrit1 = ""
strSortCrit2 = ""
strCurrentFormName = Application.CurrentObjectName
End Sub

Public Sub RunSort()
strOrderBy = strSortCrit1 & strSortCrit2
Forms!strCurrentFormName!OrderBy = strOrderBy
Forms!strCurrentFormName!OrderByOn = True
End Sub

' *************************************************************
FORM MODULE

Public Sub SortBySort_Click()
PrepSort
strSortCrit1 = "acSort1, "
strSortCrit2 = "acAssetClass, "
RunSort
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top