Hi
here's my problem:
i need to know how to write some code that will allow me to read/write data from a textbox to a .txt file
The hard bit is that the .txt file will need to be read/written to a directory that will be different for each user. Let me explain it in a bit more detail.
My program is linked to a database. When users log on to my program their userid is saved to a .txt file called "login.txt". The "login.txt" file is also loaded into a label on my program called "lblUserId".
Let's say the directory that users save their data in is App.Path & "\Docs\userid\". If userid "Jane" logs in, i want her data to be saved in "\Docs\Jane\", and so forth.
I experimented with some code, but none worked. A sample of the approach i was taking is below:
Private Sub Form_Load()
' Load login.txt into lblUserID
Open App.Path & "\login.txt" For Input As #1
Line Input #1, Data
lblUserID.Caption = lblUserID.Caption & Data
Close #1
' Make a new directory with the userid name
MkDir (App.Path & "\Docs\" & lblUserID.Caption)
End Sub
------------------------------------------------------------
Private Sub cmdSave_Click()
' Save data from Text1 to text1.txt in the user's "userid" directory
Open App.Path & "\Docs\" & lblProgID.Caption & "\text1.txt" For Output As #1
Print #1, Text1.Text
Close #1
End Sub
This approach works FINE, but only if the user logs in only once! If the user logs in twice, the MkDir line of code brings up "Run-time error '75': Path/File Access Error", basically cos the directory already exists. If i take out the MkDir lines, then i get "Run-time error '76': Path not found".
I'm sure i am probably just missing one crucial point, but i am sooo confused!! Could someone PLEASE PLEASE PLEASE help me with this little, yet EXTREAMLY important problem.
Thank you!
here's my problem:
i need to know how to write some code that will allow me to read/write data from a textbox to a .txt file
The hard bit is that the .txt file will need to be read/written to a directory that will be different for each user. Let me explain it in a bit more detail.
My program is linked to a database. When users log on to my program their userid is saved to a .txt file called "login.txt". The "login.txt" file is also loaded into a label on my program called "lblUserId".
Let's say the directory that users save their data in is App.Path & "\Docs\userid\". If userid "Jane" logs in, i want her data to be saved in "\Docs\Jane\", and so forth.
I experimented with some code, but none worked. A sample of the approach i was taking is below:
Private Sub Form_Load()
' Load login.txt into lblUserID
Open App.Path & "\login.txt" For Input As #1
Line Input #1, Data
lblUserID.Caption = lblUserID.Caption & Data
Close #1
' Make a new directory with the userid name
MkDir (App.Path & "\Docs\" & lblUserID.Caption)
End Sub
------------------------------------------------------------
Private Sub cmdSave_Click()
' Save data from Text1 to text1.txt in the user's "userid" directory
Open App.Path & "\Docs\" & lblProgID.Caption & "\text1.txt" For Output As #1
Print #1, Text1.Text
Close #1
End Sub
This approach works FINE, but only if the user logs in only once! If the user logs in twice, the MkDir line of code brings up "Run-time error '75': Path/File Access Error", basically cos the directory already exists. If i take out the MkDir lines, then i get "Run-time error '76': Path not found".
I'm sure i am probably just missing one crucial point, but i am sooo confused!! Could someone PLEASE PLEASE PLEASE help me with this little, yet EXTREAMLY important problem.
Thank you!