I have a file that pings some data to an external file. Everything works great. I'd like to expand on it, if possible, though. This file will be given to 6 different groups of people. Each person will have to select their group from a drop down box. Depending on which group they are in, I need a different external file to be chosen. I don't know if a variable can be added to the current code to add in those different group choices or not. I'm curious if someone might can take a look at it and see if it can be altered to accommodate what I'm trying to achieve?
Rich (BB code):
Sub LogInformation(LogMessage As String)
Const LogFileName As String = "P:\Engineering\Engineering Tool Logs\Group1.txt"
//Const LogFileName As String = "P:\Engineering\Engineering Tool Logs\Group2.txt"
//Const LogFileName As String = "P:\Engineering\Engineering Tool Logs\Group3.txt"
//Can I do something like "P:\Engineering\Engineering Tool Logs\" & " Sheets = (Data Handling) Range = (F2) & ".txt"
Dim FileNum As Integer
FileNum = FreeFile ' next file number
Open LogFileName For Append As #FileNum ' creates the file if it doesn't exist
Print #FileNum, LogMessage ' write information at the end of the text file
Close #FileNum ' close the file
End Sub
Public Sub DisplayLastLogInformation()
Const LogFileName As String = "P:\Engineering\Engineering Tool Logs\Group1.txt"
//Const LogFileName As String = "P:\Engineering\Engineering Tool Logs\Group2.txt"
//Const LogFileName As String = "P:\Engineering\Engineering Tool Logs\Group3.txt"
// Can I do someting like "P:\Engineering\Engineering Tool Logs\" & " Sheets = (Data Handling) Range = (F2) & ".txt"
Dim FileNum As Integer, tLine As String
FileNum = FreeFile ' next file number
Open LogFileName For Input Access Read Shared As #f ' open the file for reading
Do While Not EOF(FileNum)
Line Input #FileNum, tLine ' read a line from the text file
Loop ' until the last line is read
Close #FileNum ' close the file
MsgBox tLine, vbInformation, "Last log information:"
End Sub
Sub DeleteLogFile(FullFileName As String)
On Error Resume Next ' ignore possible errors
Kill FullFileName ' delete the file if it exists and it is possible
On Error GoTo 0 ' break on errors
End Sub