J
JustATech
Software used: Access 2007/WinXp Pro.
Hello all.
I apologize for such a long post. I'm relatively new to the Access
programming circle and am going nuts trying to figure out what I'm doing
wrong in trying to get the following idea to work.
I currently have a form which contains 1 subform. Both forms each have a
bound control that I am trying to update when the data it contains is input
or altered. The string parameter I pass to the update function I use
(CapitalizeText) is declared by the data in the control(s). This same
function (CapitalizeText) is not only present in both forms, but also
identical in code. Each appropriate control's AfterUpdate event calls their
corresponding CapitalizeText function perfectly and the data is changed
successfully without any problems.
I know it's good practice to just have 1 standalone module that contains the
update code process and then just call the module whenever I need it, but
this is where my problem occurs in trying to implement this change.
My problem is that I receive the following error message when compiling:
Microsoft Visual Basic
Compile Error:
Expected variable or procedure, not module
Here's the original code in a control's AfterUpdate event on the subform
(this is similar for the control on the main form - the exception being the
name of the control and its bound field):
Private Sub cboSiteName_AfterUpdate()
If Not IsNull(Me.cboSiteName) Then
Dim strTempName As String 'NOTE: This should not needed here when
using the standalone module.
strTempName = Trim(Me.[SiteName])
Call CapitalizeText(strTempName) 'Convert the string.
Me.cboSiteName = strTempName 'Store the newly converted string
into the table.
End If
End Sub
The following is the update function that is present in both form modules at
the moment:
Public Function CapitalizeText(strTempName As String)
'Capitalizes each separate word that follows a space in the newly entered
string.
Dim lngSpacePos As Long
'First: Ensure that the very first letter of the string is a capital.
strTempName = UCase(Left(strTempName, 1)) & Mid(strTempName, 2)
'Second: Loop through the rest of the string to capitalize each separate
word.
lngSpacePos = 1 'Initialize the loop counter.
Do
lngSpacePos = InStr(lngSpacePos, strTempName, " ", vbBinaryCompare)
If lngSpacePos > 0 Then
strTempName = Left(strTempName, lngSpacePos) & _
UCase(Left(Right(strTempName, Len(strTempName) -
lngSpacePos), 1)) & _
Mid(strTempName, lngSpacePos + 2)
lngSpacePos = lngSpacePos + 1
Else
Exit Do
End If
Loop
End Function
Here is the standalone module code that I would like to be called instead of
having the above function present in both forms:
Option Compare Database
Dim strTempName As String
Public Function CapitalizeText(strTempName As String)
'Capitalizes each separate word that follows a space in the newly entered
string.
Dim lngSpacePos As Long
'First: Ensure that the very first letter of the string is a capital.
strTempName = UCase(Left(strTempName, 1)) & Mid(strTempName, 2)
'Second: Loop through the rest of the string to capitalize each separate
word.
lngSpacePos = 1 'Initialize the loop counter.
Do
lngSpacePos = InStr(lngSpacePos, strTempName, " ", vbBinaryCompare)
If lngSpacePos > 0 Then
strTempName = Left(strTempName, lngSpacePos) & _
UCase(Left(Right(strTempName, Len(strTempName) -
lngSpacePos), 1)) & _
Mid(strTempName, lngSpacePos + 2)
lngSpacePos = lngSpacePos + 1
Else
Exit Do
End If
Loop
End Function
What am I doing wrong?
Hello all.
I apologize for such a long post. I'm relatively new to the Access
programming circle and am going nuts trying to figure out what I'm doing
wrong in trying to get the following idea to work.
I currently have a form which contains 1 subform. Both forms each have a
bound control that I am trying to update when the data it contains is input
or altered. The string parameter I pass to the update function I use
(CapitalizeText) is declared by the data in the control(s). This same
function (CapitalizeText) is not only present in both forms, but also
identical in code. Each appropriate control's AfterUpdate event calls their
corresponding CapitalizeText function perfectly and the data is changed
successfully without any problems.
I know it's good practice to just have 1 standalone module that contains the
update code process and then just call the module whenever I need it, but
this is where my problem occurs in trying to implement this change.
My problem is that I receive the following error message when compiling:
Microsoft Visual Basic
Compile Error:
Expected variable or procedure, not module
Here's the original code in a control's AfterUpdate event on the subform
(this is similar for the control on the main form - the exception being the
name of the control and its bound field):
Private Sub cboSiteName_AfterUpdate()
If Not IsNull(Me.cboSiteName) Then
Dim strTempName As String 'NOTE: This should not needed here when
using the standalone module.
strTempName = Trim(Me.[SiteName])
Call CapitalizeText(strTempName) 'Convert the string.
Me.cboSiteName = strTempName 'Store the newly converted string
into the table.
End If
End Sub
The following is the update function that is present in both form modules at
the moment:
Public Function CapitalizeText(strTempName As String)
'Capitalizes each separate word that follows a space in the newly entered
string.
Dim lngSpacePos As Long
'First: Ensure that the very first letter of the string is a capital.
strTempName = UCase(Left(strTempName, 1)) & Mid(strTempName, 2)
'Second: Loop through the rest of the string to capitalize each separate
word.
lngSpacePos = 1 'Initialize the loop counter.
Do
lngSpacePos = InStr(lngSpacePos, strTempName, " ", vbBinaryCompare)
If lngSpacePos > 0 Then
strTempName = Left(strTempName, lngSpacePos) & _
UCase(Left(Right(strTempName, Len(strTempName) -
lngSpacePos), 1)) & _
Mid(strTempName, lngSpacePos + 2)
lngSpacePos = lngSpacePos + 1
Else
Exit Do
End If
Loop
End Function
Here is the standalone module code that I would like to be called instead of
having the above function present in both forms:
Option Compare Database
Dim strTempName As String
Public Function CapitalizeText(strTempName As String)
'Capitalizes each separate word that follows a space in the newly entered
string.
Dim lngSpacePos As Long
'First: Ensure that the very first letter of the string is a capital.
strTempName = UCase(Left(strTempName, 1)) & Mid(strTempName, 2)
'Second: Loop through the rest of the string to capitalize each separate
word.
lngSpacePos = 1 'Initialize the loop counter.
Do
lngSpacePos = InStr(lngSpacePos, strTempName, " ", vbBinaryCompare)
If lngSpacePos > 0 Then
strTempName = Left(strTempName, lngSpacePos) & _
UCase(Left(Right(strTempName, Len(strTempName) -
lngSpacePos), 1)) & _
Mid(strTempName, lngSpacePos + 2)
lngSpacePos = lngSpacePos + 1
Else
Exit Do
End If
Loop
End Function
What am I doing wrong?