473,815 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with For...Next Loop and Other Questions

JodiPhillips
26 New Member
Hello All,

I'm trying to limit the number of attempts a user has to log into an MS Access 2003 database, but am having very little success.

My current code for log in is as follows (and thanks to all previous posters whose ideas and code I have taken from these forums to get me this far!!)

UserId comes in from a combo box also on the same form, the focus is then shifted to the password textbox for password entry and then the user clicks on the command button below.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdLogOn_Click()
  2. Dim sPswd As String
  3.  
  4.  
  5.         If IsNull(Me!cboUserID) = True Or IsNull(Me!txtPass) = True Then
  6.             MsgBox "please enter a valid userid and password"
  7.             Exit Sub
  8.         End If
  9.  
  10.         sPswd = Nz(DLookup("txtpword", "tblLogIn", "txtUserID='" & Me!cboUserID & " ' "), "")
  11.         Debug.Print sPswd
  12.  
  13.         If Me!txtPass <> sPswd Then
  14.             MsgBox "Invalid UserID/Password", vbOKOnly, "Try Again"
  15.             Exit Sub
  16.         End If
  17.  
  18.  
  19. DoCmd.Close acForm, "frmLogOn", acSaveNo
  20. DoCmd.OpenForm ("Start Form CL&D")
  21.  
  22. End Sub
I'm not sure where to put the For statement. I have tried at various points but end up with a lost Next statement, or the users have no limits to the number of attempts.

My tentative For code is as follows:

Expand|Select|Wrap|Line Numbers
  1. Dim intAttempts as integer
  2.  
  3. For intAttempts = 0 to 3 Step 1
  4. Next intAttempts
  5.  
  6. If intAttempts > 3 Then
  7. MsgBox "You do not have authority to access this database. Contact your support team",vbcritical,"Restricted Access!"
  8. Application.Quit
  9. End If
  10.  
Can anyone point me in the right direction on where the various For...Nexts should go, or if I am missing something from the code or using the wrong type of loop? Any help with this will be much appreciated. I've read through the help files within access on the loops and its still not clear to me.

Also, I want to AllowBypasskey = False in a procedure(? if that is the correct thing to call it) so that users cannot just Shift-Click into the database - I have a splash set up that is in pop up mode on start up and I want users to move through pages and forms in a specific direction. To disable the bypass do I have to do a create procedure before I can change it? And do I do this as a new module?

Another thing I would like to do is if the database is opened in anyway by anyone or attempt to open I would like to send an email to myself as soon as it is accessed. I can't set a password on the database for a number of reasons, but would like an audit trail of when the database is opened not just logged into. Is this doable? If so, could anyone point me in the how to direction so that I can research it. I don't know where to start looking for info on this one.

Last question - yes I know I'm being greedy, but this should be enough to keep me to browsing for the next six months I promise *wink*,

I want to run a query off the value in txtpass (as above) but if I put [Forms!].[frmLogOn!].[txtpass].[Afterupdate] into the criteria line for the query it gives me a parameter box to complete. Is there a way to specify the value thats entered at login (during the execution of the code above) directly into the query without the user having to reenter their userid? The query basically just runs off and grabs records from a table for their team members.

Many thanks =)

Jodi
May 28 '07 #1
3 2211
nico5038
3,080 Recognized Expert Specialist
You don't need various for next loops.

Just define before all sub's in the form's code your login counter like:

Expand|Select|Wrap|Line Numbers
  1. dim intLogins as Integer
  2.  
  3. ' Now in the login code use
  4.  
  5. sub Login()
  6.  
  7. intLogins = intLogins + 1
  8.  
  9. IF intLogins > 3 then 
  10.     msgbox "No more logins"
  11.     docmd.quit
  12. endif
  13.  
  14. ' herethe other code for testing
  15.  
  16. end sub
  17.  
Getting the idea ?

Nic;o)
May 28 '07 #2
JodiPhillips
26 New Member
Nic,

That did the trick, just copied the sub that you provided and called it from within the logon sub.

Many many thanks!

Jodi
May 29 '07 #3
nico5038
3,080 Recognized Expert Specialist
Glad I could help, success with your application !

Nic;o)
May 29 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
10654
by: Prasanna | last post by:
Hi All Nice to be in this Forum. I have questions to ask on UTL_FILE :roll: Let me explain the concept 1.When the net is down the user will take the records into on floppy(CLIENT 2.When the net is up he will update the database(SERVER) with all th trasaction including the records which he taken into the floppy He creates one text file in the floppy. The records in that text fil
9
11532
by: kwindham | last post by:
This program doesn't seem like it should be too hard, but I cannot figure it out. Here is the assignment: Password Verifier - Write a program to verify passwords, satisfying the following specifications: ALGORITHM: 1. Ask the user to input a possible password. 2. Check to see that it: - is at least 8 characters long
22
2207
by: KitKat | last post by:
I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam 7, and Cam 8. Well it does that but it also needs to change the file name to the same folder where the file is being grabbed, BUT it doesn't. I have tried and tried.....please help example: C:\Projects\Darryl\Queue Review Files\2-24\Cam 7\Cam7-20060224170000-01.jpg Cam7 but all I keep getting is Cam1, as the beginning of the jpg name,...:( HELP!
6
1686
by: JOSII | last post by:
Getting a string of boolean value into and out of the registry is no problem. Here's the problem: Although you can place an object into the registry and retreive it, I need to place an ArrayList object with 10 string items into the registry and retreive them later. I tried this: key.SetValue("lstNSXitems", lstNSX.Items) where "lstNSXitems" is the name of the subkey, and lstNSX.Items is the
15
2587
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to determine who needs to receive the text message then send the message to the address. Only problem is, the employee may receive up to 4 of the same messages because each thread gets the recors then sends the message. I need somehow to prevent...
0
5578
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
6
2493
by: portCo | last post by:
Hello there, I am creating a vb application which is some like like a questionare. Application read a text file which contains many questions and display one question and the input is needed from user to calculate the score. Here is a problem. I can read a text file. However, it's read whole file at a time. So,
2
19319
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that iterates a specified number of times, requires you to also implement or decrement some sort of Loop Counter, while a For...Next Loop does that work for you. Both Loops will provide the same results, but the For...Next Loop is substantially faster. One...
32
2801
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put some new ones on. In my code I am doing the following: For Each ctrl In tpMain.Controls If TypeOf (ctrl) Is CheckBox Then If ctrl.Name.StartsWith("chkS") Then ctrl.Visible = False
0
9737
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
9613
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,...
1
10430
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10147
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...
0
9227
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
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
5712
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4360
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3032
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.