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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

External Name not Defined

Status
Not open for further replies.

nancier

MIS
Dec 27, 2004
50
US
Hi,
I have a text box on a form called Text2. I'm trying to get the module below to find the form on this line but am getting an error "External Name not defined" on this line. How do I fix this? Thanks

strNewText = "tblAmount.[" & Text2 & "]"



Public Function Command5_Click()
Dim StartLine As Long, StartColumn As Long
Dim EndLine As Long, EndColumn As Long
Dim strLine As String, strNewLine As String
Dim intChr As Integer, intBefore As Integer, intAfter As Integer
Dim strLeft As String, strRight As String
Dim strSearchText As String, strNewText


' The string you are searching for is:
strSearchText = "tblStupload.[NUM-1]"


' The replacement string is:
strNewText = "tblAmount.[" & Text2 & "]"


' Open the Module you want to modify.
DoCmd.OpenModule "mdlDoItAll"

' Set the Created Code Modules as the Object.
Set MyModule = Application.Modules("mdlDoItAll")

' Search for string.
If MyModule.Find(strSearchText, StartLine, StartColumn, EndLine, _
EndColumn) Then

' Store text of line containing string.
strLine = MyModule.Lines(StartLine, Abs(EndLine - StartLine) + 1)

' Determine length of line.
intChr = Len(strLine)

' Determine number of characters preceding search text.
intBefore = StartColumn - 1

' Determine number of characters following search text.
intAfter = intChr - CInt(EndColumn - 1)

' Store characters to left of search text.
strLeft = Left$(strLine, intBefore)

' Store characters to right of search text.
strRight = Right$(strLine, intAfter)

' Construct string with replacement text.
strNewLine = strLeft & strNewText & strRight

' Replace the original line.
MyModule.ReplaceLine StartLine, strNewLine

Else
MsgBox "Text not found."
End If

' Save and close the module.
DoCmd.Save acModule, MyModule
DoCmd.Close acModule, MyModule, acSaveYes

End Function
 
If this code is in a module you have to tell where Text2 is located
So it would be
Code:
strNewText = "tblAmount.[" & Forms!FormName!Text2.Text & "]"
If the module is in the same form on which Text2 located then
Code:
strNewText = "tblAmount.[" & Me.Text2.Text & "]"


Zameer Abdulla
Jack of Visual Basic Programming, Master in Dining & Sleeping
Visit Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top