From: Douglas J. Steele on
Hold on, my one answer was inaccurate! If all you're doing on the second
command button is reading the data from the file, open it for Input, not
Output!

Open "C:\Accounts\Users\" & username & ".txt" For Input As #intFile

You'd use

Open "C:\Accounts\Users\" & username & ".txt" For Output Shared As #intFile

if you were doing both reads and writes in the same routine.


--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/djsteele
Co-author: "Access 2010 Solutions", published by Wiley
(no e-mails, please!)



"Douglas J. Steele" <NOSPAM_djsteele(a)NOSPAM_gmail.com> wrote in message
news:ep1lmaOBLHA.4584(a)TK2MSFTNGP06.phx.gbl...
> "Bob H" <bob(a)despammer.com> wrote in message
> news:edudnd0UkMVw8ZfRnZ2dnUVZ8kidnZ2d(a)giganews.com...
>>
>> Update:
>> I have used this line to create a text file with given information:
>>
>> Open "C:\Accounts\Users\" + username + ".txt" For Output As #1
>> Print #1, Text23
>> Print #1, Text25
>
> I guess I should have highlighted in my previous reply that you should
> never refer to file handles by hard-coded numbers. While it may work fine
> for you, if other applications are reading or writing to files at the same
> time, you can run into problems. You should ALWAYS use the FreeFile
> function, even if you're positive no other applications will ever be
> running concurrent with yours.
>
> Dim intFile As Integer
>
> intFile = FreeFile()
> Open "C:\Accounts\Users\" & username & ".txt" For Output As #intFile
> Print #intFile, Text23
> Print #intFile, Text25
>
> You should also use & for concatenating text, not +.
>
>> But now on another cmd button I want access to read that said information
>> in that text file, and grant access.
>> With this line:
>>
>> Open "C:\Accounts\Users\" + username + ".txt" For Output As #2
>> Input #2, openfile
>> If username.Text = openfile Then
>> Input #2, datafile
>
> Try using
>
> Open "C:\Accounts\Users\" & username & ".txt" For Output Shared As #2
>
>> Access throws up a runtime error 54 'Bad File mode' at Input #2 ,
>> openfile openfile
>>
>> Also the information in the previously created text file has been
>> deleted.
>
> As you've found, opening a file For Output deletes the previous file if it
> exists. use For Append. That will create the file if it doesn't already
> exist, and append to the file if it does.
>
> --
> Doug Steele, Microsoft Access MVP
> http://www.AccessMVP.com/djsteele
> Co-author: "Access 2010 Solutions", published by Wiley
> (no e-mails, please!)
>
>
>
>

From: Douglas J. Steele on
Just for the sake of completeness, Daniel's reply is correct. Somehow the
required spaces didn't appear in the post.

> username = Me!Text23 & vbNullString
> If Len(username) = 0 Then
> MsgBox "Enter a Username !"
> Else
> If Len(Me!Text25 & vbNullString) = 0 Then


--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele/AccessIndex.html
Co-author: "Access 2010 Solutions", published by Wiley
(no private e-mails, please)


"Bob H" <bob(a)despammer.com> wrote in message
news:wuOdnWeHKJBcx5TRnZ2dnUVZ8hadnZ2d(a)giganews.com...
> Thanks for the coding but now I get runtime error 2465 at the line:
> username = Me!Text23& vbNullString.
>
> Thanks
>
> On 04/06/2010 20:21, Douglas J. Steele wrote:
>> There is no App object in Access.
>>
>> Private Sub CreateAcc_Click()
>> Dim intFile As Integer
>> Dim username As String
>>
>> username = Me!Text23& vbNullString
>> If Len(username) = 0 Then
>> MsgBox "Enter a Username !"
>> Else
>> If Len(Me!Text25& vbNullString) = 0 Then
>> MsgBox "Enter a Password !"
>> Else
>> intFile = FreeFile()
>> Open CurrentProject.Path& "\Accounts\Users\"& username& ".txt"
>> For
>> Output As #intFile
>> Print #intFile, Me!Text23
>> Print #intFile, Me!Text25
>> Close #intFile
>> End If
>> End If
>>
>> End Sub
>>
>>
>


From: Bob H on
On 05/06/2010 20:44, Douglas J. Steele wrote:
> Hold on, my one answer was inaccurate! If all you're doing on the second
> command button is reading the data from the file, open it for Input, not
> Output!
>
> Open "C:\Accounts\Users\" & username & ".txt" For Input As #intFile
>
> You'd use
>
> Open "C:\Accounts\Users\" & username & ".txt" For Output Shared As #intFile
>
> if you were doing both reads and writes in the same routine.
>
>

Ok, this is the code I am using to login to an account, using account
creation files.
Basically I want Access 2007 to read a previously created file, which
has the username and password in it. Once it has been read, then access
is granted to the whatever.

Private Sub cmdLogin_Click()
Dim openfile As String
Dim datafile As String
Dim intFile As Integer
openfile = Text1
datafile = Text2

If Text1 = "" Then
MsgBox "Please Enter a Username"
Else
If Text2 = "" Then
MsgBox " Please Enter a password"
Else
intFile = FreeFile()
Open "C:\Accounts\Users\" & Text1 & ".txt" For Input As #intFile

Input #2, openfile <<< I am getting a runtime error here as before

If Text1 = openfile Then
Input #2, datafile
If Text2 = datafile Then
MsgBox "Granted Access"
Else
MsgBox "Denied Access"
End If
End If
Close #2
End If
End If
End Sub

I know there is something wrong with it at that line but I don't know
what else to change it to.

Thanks
From: Douglas J. Steele on
You've still got the #2 everywhere in your code! That should be #intFile.

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/djsteele
Co-author: "Access 2010 Solutions", published by Wiley
(no e-mails, please!)



"Bob H" <bob(a)despammer.com> wrote in message
news:NJmdnWdzTLnI9pbRnZ2dnUVZ8o-dnZ2d(a)giganews.com...
> On 05/06/2010 20:44, Douglas J. Steele wrote:
>> Hold on, my one answer was inaccurate! If all you're doing on the second
>> command button is reading the data from the file, open it for Input, not
>> Output!
>>
>> Open "C:\Accounts\Users\" & username & ".txt" For Input As #intFile
>>
>> You'd use
>>
>> Open "C:\Accounts\Users\" & username & ".txt" For Output Shared As
>> #intFile
>>
>> if you were doing both reads and writes in the same routine.
>>
>>
>
> Ok, this is the code I am using to login to an account, using account
> creation files.
> Basically I want Access 2007 to read a previously created file, which has
> the username and password in it. Once it has been read, then access is
> granted to the whatever.
>
> Private Sub cmdLogin_Click()
> Dim openfile As String
> Dim datafile As String
> Dim intFile As Integer
> openfile = Text1
> datafile = Text2
>
> If Text1 = "" Then
> MsgBox "Please Enter a Username"
> Else
> If Text2 = "" Then
> MsgBox " Please Enter a password"
> Else
> intFile = FreeFile()
> Open "C:\Accounts\Users\" & Text1 & ".txt" For Input As #intFile
>
> Input #2, openfile <<< I am getting a runtime error here as before
>
> If Text1 = openfile Then
> Input #2, datafile
> If Text2 = datafile Then
> MsgBox "Granted Access"
> Else
> MsgBox "Denied Access"
> End If
> End If
> Close #2
> End If
> End If
> End Sub
>
> I know there is something wrong with it at that line but I don't know what
> else to change it to.
>
> Thanks

From: Bob H on
On 06/06/2010 14:49, Douglas J. Steele wrote:
> You've still got the #2 everywhere in your code! That should be #intFile.
>

Thanks for your time and help, as that has done the job for me now.