A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

this code doesn't work fully



 
 
Thread Tools Display Modes
  #1  
Old June 4th, 2010, 07:39 PM posted to microsoft.public.access.forms
Bob H[_4_]
external usenet poster
 
Posts: 161
Default this code doesn't work fully

I am trying to create a login box for an Access 2007 database using some
VB8 code I found:

Private Sub CreateAcc_Click()
Dim username As String
username = Text23
If Text23 = "" Then
MsgBox "Enter a Username !"
Else
If Text25 = "" Then
MsgBox "Enter a Password !"
Else
Open app.Path & "\Accounts\Users\" + username + ".txt" For Output As #1
Print #1, Text23
Print #1, Text25
Close #1
End If
End If

End Sub

It runs up to the line 'Open app.path etc, then get a runtime error 424,
Object required.
What would that be, and what should the correct syntax be for Open app.path

Thanks
Ads
  #2  
Old June 4th, 2010, 08:15 PM posted to microsoft.public.access.forms
Ken Snell
external usenet poster
 
Posts: 177
Default this code doesn't work fully

Open CurrentProject.Path & "\Accounts\Users\" + username + ".txt" For
Output As #1
--

Ken Snell
http://www.accessmvp.com/KDSnell/


"Bob H" wrote in message
...
I am trying to create a login box for an Access 2007 database using some
VB8 code I found:

Private Sub CreateAcc_Click()
Dim username As String
username = Text23
If Text23 = "" Then
MsgBox "Enter a Username !"
Else
If Text25 = "" Then
MsgBox "Enter a Password !"
Else
Open app.Path & "\Accounts\Users\" + username + ".txt" For Output As
#1
Print #1, Text23
Print #1, Text25
Close #1
End If
End If

End Sub

It runs up to the line 'Open app.path etc, then get a runtime error 424,
Object required.
What would that be, and what should the correct syntax be for Open
app.path

Thanks



  #3  
Old June 4th, 2010, 08:21 PM posted to microsoft.public.access.forms
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default this code doesn't work fully

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


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

"Bob H" wrote in message
...
I am trying to create a login box for an Access 2007 database using some
VB8 code I found:

Private Sub CreateAcc_Click()
Dim username As String
username = Text23
If Text23 = "" Then
MsgBox "Enter a Username !"
Else
If Text25 = "" Then
MsgBox "Enter a Password !"
Else
Open app.Path & "\Accounts\Users\" + username + ".txt" For Output As
#1
Print #1, Text23
Print #1, Text25
Close #1
End If
End If

End Sub

It runs up to the line 'Open app.path etc, then get a runtime error 424,
Object required.
What would that be, and what should the correct syntax be for Open
app.path

Thanks



  #4  
Old June 4th, 2010, 08:50 PM posted to microsoft.public.access.forms
Daniel Pineault
external usenet poster
 
Posts: 658
Default this code doesn't work fully

To pull the path of your currently open database you'd use:

Application.CurrentProject.Path
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Bob H" wrote:

I am trying to create a login box for an Access 2007 database using some
VB8 code I found:

Private Sub CreateAcc_Click()
Dim username As String
username = Text23
If Text23 = "" Then
MsgBox "Enter a Username !"
Else
If Text25 = "" Then
MsgBox "Enter a Password !"
Else
Open app.Path & "\Accounts\Users\" + username + ".txt" For Output As #1
Print #1, Text23
Print #1, Text25
Close #1
End If
End If

End Sub

It runs up to the line 'Open app.path etc, then get a runtime error 424,
Object required.
What would that be, and what should the correct syntax be for Open app.path

Thanks
.

  #5  
Old June 4th, 2010, 08:57 PM posted to microsoft.public.access.forms
Bob H[_4_]
external usenet poster
 
Posts: 161
Default this code doesn't work fully

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



  #6  
Old June 4th, 2010, 09:44 PM posted to microsoft.public.access.forms
Daniel Pineault
external usenet poster
 
Posts: 658
Default this code doesn't work fully

Try

username = Me!Text23 & vbNullString

Have you setup your form to have a control name Text23 which has the user's
name?!
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Bob H" wrote:

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



.

  #7  
Old June 4th, 2010, 11:17 PM posted to microsoft.public.access.forms
Bob H[_4_]
external usenet poster
 
Posts: 161
Default this code doesn't work fully

On 04/06/2010 21:44, Daniel Pineault wrote:
Try

username = Me!Text23& vbNullString

Have you setup your form to have a control name Text23 which has the user's
name?!


If you mean something like Text23.Username, then no I haven't.
But as I am attempting to create an account, the username could be anything.
Or should I have pre defined usernames and passwords.

Thanks
  #8  
Old June 4th, 2010, 11:23 PM posted to microsoft.public.access.forms
Bob H[_4_]
external usenet poster
 
Posts: 161
Default this code doesn't work fully

On 04/06/2010 20:50, Daniel Pineault wrote:
To pull the path of your currently open database you'd use:

Application.CurrentProject.Path


Ok thanks, but where does this line fit in with the other lines.
Do I have to actually create the path first then put it in the line.

Thanks
  #9  
Old June 5th, 2010, 04:27 PM posted to microsoft.public.access.forms
Bob H[_4_]
external usenet poster
 
Posts: 161
Default this code doesn't work fully

On 04/06/2010 23:23, Bob H wrote:
On 04/06/2010 20:50, Daniel Pineault wrote:
To pull the path of your currently open database you'd use:

Application.CurrentProject.Path


Ok thanks, but where does this line fit in with the other lines.
Do I have to actually create the path first then put it in the line.

Thanks


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

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

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.

Thanks
  #10  
Old June 5th, 2010, 08:38 PM posted to microsoft.public.access.forms
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default this code doesn't work fully

"Bob H" wrote in message
...

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!)




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:52 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright 2004-2017 OfficeFrustration.
The comments are property of their posters.