These two functions have alot of repeated code. Anyone know if I could combine these somehow? Thanks
Option Compare Database
Option Explicit
Dim MyModule As Module
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.[" & Forms!Form1!Text2 & "] AS [NUM-1]"
' 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
End Function
Function Command9_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-2]"
' The replacement string is:
strNewText = "tblAmount.[" & Forms!Form1!Text3 & "] AS [NUM-2]"
' 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
Option Compare Database
Option Explicit
Dim MyModule As Module
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.[" & Forms!Form1!Text2 & "] AS [NUM-1]"
' 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
End Function
Function Command9_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-2]"
' The replacement string is:
strNewText = "tblAmount.[" & Forms!Form1!Text3 & "] AS [NUM-2]"
' 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