473,320 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Maximum length of an If Then line in VBA

Is there a maximum length in VBA of a line containing stuff like the
following:
If password = "1234" or password = "1235" or password = ............... Then

It seems to me that at some stage, I add an extra password onto the end of
the line and it does not work. I assumed it might be 255 characters, but
the line that works is much longer than that.

dixie

Nov 13 '05 #1
12 2174
Dixie,

It seems you must have a lot of passwords. Assuming you have a form called
"MyForm" and a field named "MyPassword" to enter a password, consider doing
this:

Build a table called TblPassword and put all your passwords in a field named
Password. Then where you are using the If statement, use this instead:

If DCount("*","TblPassword","[Password] = '" & Forms!MyForm!MyPassword & "'")
Then
<<Do whatever, the password that was entered is in the list>>
Else
MsgBox "The Password that was entered is not in the list"
End If
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"dixie" <di****@dogmail.com> wrote in message
news:8j****************@nnrp1.ozemail.com.au...
Is there a maximum length in VBA of a line containing stuff like the
following:
If password = "1234" or password = "1235" or password = ............... Then

It seems to me that at some stage, I add an extra password onto the end of
the line and it does not work. I assumed it might be 255 characters, but
the line that works is much longer than that.

dixie

Nov 13 '05 #2
dixie wrote:
Is there a maximum length in VBA of a line containing stuff like the
following:
If password = "1234" or password = "1235" or password =
............... Then

It seems to me that at some stage, I add an extra password onto the
end of the line and it does not work. I assumed it might be 255
characters, but the line that works is much longer than that.

dixie


It would be more efficient to use a Select Case construct. That could be
any length you like and alot more readable.

e.g

Select Case password
Case Is = "1234"
'run code here
Case Is = "1235"
'run code here
Case Is = "1236"
'run code here
Case Is = "1237"
'run code here

Case Is = "1238"
'run code here
End Select
Nov 13 '05 #3
On Mon, 19 Jul 2004 07:52:08 +1000, "dixie" <di****@dogmail.com>
wrote:

Unless this is a rare exception (but then you would have pointed that
out in your post), this sounds like very bad application design. If
someone wanted to change his or her password, they would have to ask
you to please do so? Sounds like job security to me.
Rather as was already pointed out, users should be able to maintain
their own password, which you would store (perhaps encrypted) in a
Users table. Administrators should be able to reset passwords.

Alternatively, consider that the user is already logged into Windows,
and you can ask Windows what the current username is
(http://www.mvps.org/access/api/api0008.htm). In most cases no further
password should be necessary; the fact that the user was able to log
into Windows is proof enough that she is who she says she is.

-Tom.
Is there a maximum length in VBA of a line containing stuff like the
following:
If password = "1234" or password = "1235" or password = ............... Then

It seems to me that at some stage, I add an extra password onto the end of
the line and it does not work. I assumed it might be 255 characters, but
the line that works is much longer than that.

dixie


Nov 13 '05 #4
"dixie" <di****@dogmail.com> wrote in
news:8j****************@nnrp1.ozemail.com.au:
Is there a maximum length in VBA of a line containing stuff like
the following:
If password = "1234" or password = "1235" or password =
............... Then

It seems to me that at some stage, I add an extra password onto
the end of the line and it does not work. I assumed it might be
255 characters, but the line that works is much longer than that.


The underscore character ("_") can be used to continue lines:

If password = "1234" _
Or password = "1235" _
Or password = "1236" _
Or password = "1237" _
Or password = "1238" Then

Others have suggested SELECT CASE, but gave you an example that
wasn't terribly efficient. This would be preferable:

Select Case Password
Case "1234", "1235", "1236", "1237", "1238"
[do whatever you do when the password is valid]
Case Else
[do whatever you do when it isn't]
End Select

Of course, to reiterate what others have said, storing passwords in
code is not a very good design.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #5
Tom, what you are suggesting about storing passwords in a table is what I
wanted to do, but I didn't, as I was afraid that someone who could access
the tables could read all the passwords. But, if they can be encrypted,
this would solve that. How do you encrypt passwords held in a table? BTW,
the reason the Windows password is not useable is that there are many
password protected areas with different passwords depending on how much
access a user is granted.

dixie

"Tom van Stiphout" <no*************@cox.net> wrote in message
news:pu********************************@4ax.com...
On Mon, 19 Jul 2004 07:52:08 +1000, "dixie" <di****@dogmail.com>
wrote:

Unless this is a rare exception (but then you would have pointed that
out in your post), this sounds like very bad application design. If
someone wanted to change his or her password, they would have to ask
you to please do so? Sounds like job security to me.
Rather as was already pointed out, users should be able to maintain
their own password, which you would store (perhaps encrypted) in a
Users table. Administrators should be able to reset passwords.

Alternatively, consider that the user is already logged into Windows,
and you can ask Windows what the current username is
(http://www.mvps.org/access/api/api0008.htm). In most cases no further
password should be necessary; the fact that the user was able to log
into Windows is proof enough that she is who she says she is.

-Tom.
Is there a maximum length in VBA of a line containing stuff like the
following:
If password = "1234" or password = "1235" or password = ............... Then
It seems to me that at some stage, I add an extra password onto the end ofthe line and it does not work. I assumed it might be 255 characters, but
the line that works is much longer than that.

dixie

Nov 13 '05 #6
Dixie, Not sure how to encrypt the data, but if you open the table in design
view, select your password field, and type in Password on the Input Mask
line. Now when someone types in the field an asterisk(*) is displayed
instead. Anyone opening the table will also see an asterisk for the
password (i.e **** for password 1234) .

--
Reggie

----------
"dixie" <di****@dogmail.com> wrote in message
news:jX***************@nnrp1.ozemail.com.au...
Tom, what you are suggesting about storing passwords in a table is what I
wanted to do, but I didn't, as I was afraid that someone who could access
the tables could read all the passwords. But, if they can be encrypted,
this would solve that. How do you encrypt passwords held in a table? BTW, the reason the Windows password is not useable is that there are many
password protected areas with different passwords depending on how much
access a user is granted.

dixie

"Tom van Stiphout" <no*************@cox.net> wrote in message
news:pu********************************@4ax.com...
On Mon, 19 Jul 2004 07:52:08 +1000, "dixie" <di****@dogmail.com>
wrote:

Unless this is a rare exception (but then you would have pointed that
out in your post), this sounds like very bad application design. If
someone wanted to change his or her password, they would have to ask
you to please do so? Sounds like job security to me.
Rather as was already pointed out, users should be able to maintain
their own password, which you would store (perhaps encrypted) in a
Users table. Administrators should be able to reset passwords.

Alternatively, consider that the user is already logged into Windows,
and you can ask Windows what the current username is
(http://www.mvps.org/access/api/api0008.htm). In most cases no further
password should be necessary; the fact that the user was able to log
into Windows is proof enough that she is who she says she is.

-Tom.
Is there a maximum length in VBA of a line containing stuff like the
following:
If password = "1234" or password = "1235" or password = ............... Then
It seems to me that at some stage, I add an extra password onto the end ofthe line and it does not work. I assumed it might be 255 characters, butthe line that works is much longer than that.

dixie


Nov 13 '05 #7
Dear PC Datasheet
I tried your code and it worked fine. What I would like to do is to have
only one password form that generically does all instances of passwords. To
do this, I will have a different field in tblPasswords for each instance of
needing to use a password (20 in all). This means that I need to pass a
different fieldname as the [Password] (domain) part for each use of the
password form so that it can choose the correct set of passwords. I can
pass a field name to a text box on the password form with OpenArgs when I
open the password form. I have been trying to get the contents of this text
box to sustitute for the [Password] bit in the DCount expression:

DCount("*","TblPassword","[Password] = '" & Forms!MyForm!MyPassword & "'")

So far no luck. Can this be done or is it too difficult?

dixie

"PC Datasheet" <no****@nospam.spam> wrote in message
news:5x****************@newsread2.news.atl.earthli nk.net...
Dixie,

It seems you must have a lot of passwords. Assuming you have a form called
"MyForm" and a field named "MyPassword" to enter a password, consider doing this:

Build a table called TblPassword and put all your passwords in a field named Password. Then where you are using the If statement, use this instead:

If DCount("*","TblPassword","[Password] = '" & Forms!MyForm!MyPassword & "'") Then
<<Do whatever, the password that was entered is in the list>>
Else
MsgBox "The Password that was entered is not in the list"
End If
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com

Nov 13 '05 #8
"dixie" <di****@dogmail.com> wrote in
news:2Y***************@nnrp1.ozemail.com.au:
Dear PC Datasheet
I tried your code and it worked fine. What I would like to do
is to have only one password form that generically does all
instances of passwords. To do this, I will have a different
field in tblPasswords for each instance of needing to use a
password (20 in all). This means that I need to pass a
different fieldname as the [Password] (domain) part for each
use of the password form so that it can choose the correct set
of passwords. I can pass a field name to a text box on the
password form with OpenArgs when I open the password form. I
have been trying to get the contents of this text box to
sustitute for the [Password] bit in the DCount expression:

DCount("*","TblPassword","[Password] = '" &
Forms!MyForm!MyPassword & "'")

So far no luck. Can this be done or is it too difficult?

dixie

Yes it can be done. But a better way is to create a two column
password table. Column 1 is the instance of passwords to use.
Column2 is the passwords: so modify your code above

DCount("*",tblPassword","Password = '" &
Forms!MyForm!MyPassword & "' AND Instance = '" &
me.openargs & "'"

Bob Quintal

PA is y I modified my email address
Nov 13 '05 #9
Great work Bob, that basically does what I need it to. I have however just
run into another problem which is to make the generic password form open the
correct form according to what password is put into it. I have made a field
called fName in tblPasswords which actually has the name of the form I want
to open and I am trying to use that to open the correct form from the
password form.

I am however having problems making that work. If I can't get it to work, I
am going to have to go back to a different form for each instance of
password

I guess I could do some form of Case structure in the password form that
opens the right form according to what is in Me.OpenArgs, but then I am
using hard coded names in the form.

Can you suggest any other way that it can be done without reverting to a
large Case 1, Case 2, Case 3 structure?

Thankyour for your help.
dixie

"Bob Quintal" <rq******@sPAmpatico.ca> wrote in message
news:Xn**********************@66.150.105.50...
"dixie" <di****@dogmail.com> wrote in
news:2Y***************@nnrp1.ozemail.com.au:
Dear PC Datasheet
I tried your code and it worked fine. What I would like to do
is to have only one password form that generically does all
instances of passwords. To do this, I will have a different
field in tblPasswords for each instance of needing to use a
password (20 in all). This means that I need to pass a
different fieldname as the [Password] (domain) part for each
use of the password form so that it can choose the correct set
of passwords. I can pass a field name to a text box on the
password form with OpenArgs when I open the password form. I
have been trying to get the contents of this text box to
sustitute for the [Password] bit in the DCount expression:

DCount("*","TblPassword","[Password] = '" &
Forms!MyForm!MyPassword & "'")

So far no luck. Can this be done or is it too difficult?

dixie

Yes it can be done. But a better way is to create a two column
password table. Column 1 is the instance of passwords to use.
Column2 is the passwords: so modify your code above

DCount("*",tblPassword","Password = '" &
Forms!MyForm!MyPassword & "' AND Instance = '" &
me.openargs & "'"

Bob Quintal

PA is y I modified my email address

Nov 13 '05 #10
rkc

"dixie" <di****@dogmail.com> wrote in message
news:q3***************@nnrp1.ozemail.com.au...
I am however having problems making that work. If I can't get it to work, I am going to have to go back to a different form for each instance of
password

I guess I could do some form of Case structure in the password form that
opens the right form according to what is in Me.OpenArgs, but then I am
using hard coded names in the form.

Can you suggest any other way that it can be done without reverting to a
large Case 1, Case 2, Case 3 structure?


How about writing some code? Maybe a function that opens a recordset
on a password table based on criteria that a password exists in the table
and opens the proper form if it does.

You have a table such as:
tblPasswords (password*, FormToOpen)
<air code>
<calling code>
if OpenCorrectForm (Forms!MyForm!MyPassword ) then
'good password
'form is open
end if
</calling code>

<OpenCorrectForm function>
Function OpenCorrectForm (pword as string) as boolean

on error got errHandler
dim rs as dao.recordset
set rs = currentdb.openrecordset ("SELECT * FROM tblPasswords " & _
"WHERE password = '"
& pword & """)

if rs.recordcount <> 0 then
docmd.openform rs!FormToOpen
OpenCorrectForm = true
end if

exitHere:
if not rs is nothing then
rs.close
set rs = nothing
end if
exit function

errHandler:
OpenCorrectForm = false
resume exitHere
end function
</OpenCorrectForm function>
</air code>
Nov 13 '05 #11
Its OK Bob, I did what I suggested and did a Select Case for the 20
possible Cases and it only took me about 10 minutes. Thanks again for your
help and the others who made suggestions.

dixie

"dixie" <di****@dogmail.com> wrote in message
news:q3***************@nnrp1.ozemail.com.au...
Great work Bob, that basically does what I need it to. I have however just run into another problem which is to make the generic password form open the correct form according to what password is put into it. I have made a field called fName in tblPasswords which actually has the name of the form I want to open and I am trying to use that to open the correct form from the
password form.

I am however having problems making that work. If I can't get it to work, I am going to have to go back to a different form for each instance of
password

I guess I could do some form of Case structure in the password form that
opens the right form according to what is in Me.OpenArgs, but then I am
using hard coded names in the form.

Can you suggest any other way that it can be done without reverting to a
large Case 1, Case 2, Case 3 structure?

Thankyour for your help.
dixie

"Bob Quintal" <rq******@sPAmpatico.ca> wrote in message
news:Xn**********************@66.150.105.50...
"dixie" <di****@dogmail.com> wrote in
news:2Y***************@nnrp1.ozemail.com.au:
Dear PC Datasheet
I tried your code and it worked fine. What I would like to do
is to have only one password form that generically does all
instances of passwords. To do this, I will have a different
field in tblPasswords for each instance of needing to use a
password (20 in all). This means that I need to pass a
different fieldname as the [Password] (domain) part for each
use of the password form so that it can choose the correct set
of passwords. I can pass a field name to a text box on the
password form with OpenArgs when I open the password form. I
have been trying to get the contents of this text box to
sustitute for the [Password] bit in the DCount expression:

DCount("*","TblPassword","[Password] = '" &
Forms!MyForm!MyPassword & "'")

So far no luck. Can this be done or is it too difficult?

dixie

Yes it can be done. But a better way is to create a two column
password table. Column 1 is the instance of passwords to use.
Column2 is the passwords: so modify your code above

DCount("*",tblPassword","Password = '" &
Forms!MyForm!MyPassword & "' AND Instance = '" &
me.openargs & "'"

Bob Quintal

PA is y I modified my email address


Nov 13 '05 #12
"dixie" <di****@dogmail.com> wrote in
news:q3***************@nnrp1.ozemail.com.au:
Great work Bob, that basically does what I need it to. I have
however just run into another problem which is to make the
generic password form open the correct form according to what
password is put into it. I have made a field called fName in
tblPasswords which actually has the name of the form I want
to open and I am trying to use that to open the correct form
from the password form.


If your openargs to the password entry screen is the name of the
password protected form, you can also use the openargs to to
specify the form to open

so

If DCount("*",tblPassword","Password = '" _
& Forms!MyForm!MyPassword _
& "' AND Instance = '" _
& me.openargs & "'" >0 then
docmd.openform openargs
else
msgbox "Password not accepted"
end if

--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Hal Vaughan | last post by:
Is there a maximum length for Javascript program lines? What about strings? Is there a limit on string length? I found some references that said the maximum string length was 256 characters,...
2
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
11
by: Leroy | last post by:
Hello, I have a question regarding the maximum number of parameters that can be passed to a procedure. In VB 6 the max was 60. What is the max for Dot Net? please and thanks.
3
by: yawnmoth | last post by:
I'm trying to figure out how big integers in PHP can be and am having some difficulty. My first idea was to try something like this: <? for ($bits=0; (1<<($bits+1)) > (1<<$bits); $bits++);...
2
by: ArtOfSpeech | last post by:
hi.... Can anyone tell me plz how to set a maximum number of (lines) to a rich text control and show only last linse when number of lines exceeds the maximum number??? i've tried to use...
7
by: Martin Pöpping | last post by:
Hello, does a String in C# have a maximum length? I tried to write a ToString Method of my class containing a hashtable. At the beginning of the method i defined a String "ret". In every...
4
by: p.numminen | last post by:
Is it possible, with CSS, to determine a certain _maximum_ width for a text, paragraph, division, etc.?
7
by: Curious | last post by:
Hi, I need advice on how to set the maximum property of my progress bar. I read a huge file so I need a progress bar when I read it. However, I don't know how many records are there in the...
53
by: Gianni Mariani | last post by:
Do you have a preference on maximum line width for C++ code? I've seen the craziest debates on this most silly of topic. I have witnessed engineers spent oodles of time fiddling with line...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.