473,932 Members | 18,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2226
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("*","Tbl Password","[Password] = '" & Forms!MyForm!My Password & "'")
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******@pcdata sheet.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.c om...
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.o zemail.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.c om...
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("*","Tbl Password","[Password] = '" & Forms!MyForm!My Password & "'")

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

dixie

"PC Datasheet" <no****@nospam. spam> wrote in message
news:5x******** ********@newsre ad2.news.atl.ea rthlink.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("*","Tbl Password","[Password] = '" & Forms!MyForm!My Password & "'") 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******@pcdata sheet.com
www.pcdatasheet.com

Nov 13 '05 #8
"dixie" <di****@dogmail .com> wrote in
news:2Y******** *******@nnrp1.o zemail.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("*","Tbl Password","[Password] = '" &
Forms!MyForm!My Password & "'")

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("*",tblP assword","Passw ord = '" &
Forms!MyForm!My Password & "' 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******@sPAmp atico.ca> wrote in message
news:Xn******** **************@ 66.150.105.50.. .
"dixie" <di****@dogmail .com> wrote in
news:2Y******** *******@nnrp1.o zemail.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("*","Tbl Password","[Password] = '" &
Forms!MyForm!My Password & "'")

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("*",tblP assword","Passw ord = '" &
Forms!MyForm!My Password & "' AND Instance = '" &
me.openargs & "'"

Bob Quintal

PA is y I modified my email address

Nov 13 '05 #10

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

Similar topics

8
4740
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, but I have a program that created a string of over 25,000 characters (the browser was Konqueror). Are there limits on these lengths? If I require a newer browser for the program I'm writing, would that change the situation?
2
28628
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
13437
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
36911
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++); echo $bits; ?>
2
1930
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 richtext.lines array to determine lines length but i can remove from it cause its of system array type and is length fixed which means i cant add or remove elements from it...
7
64863
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 iteration of my hashtable I add the content with ret += "...". After some time my programm crashes.
4
5100
by: p.numminen | last post by:
Is it possible, with CSS, to determine a certain _maximum_ width for a text, paragraph, division, etc.?
7
1185
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 file until I finish reading it. Anyone can advise me on how to set accurate maximum?
53
12185
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 breaks just to get it right. I find in general a prescriptive rule makes for markedly less readable code, which unfortunately is a subjective argument, however, the waste of time modifying code when it does not need to is not.
0
10122
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9954
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11499
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10638
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8197
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7361
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6057
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6267
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3485
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.