Computer tutorials, tips, and tricks to help you learn Microsoft Excel, Access, Word, and lots more. Visit our full site at www.ComputerLearningZone.com.
Want to make a box on your form editable only when another field meets a condition? In this example, I use Conditional Formatting to disable Credit Limit unless State is Florida. Don't forget to check for Null, or a missing state can slip through. The rule changes what you can edit on the form, not the value already stored in the table. Watch the video to see it work in both single and continuous forms.
For a complete step-by-step video tutorial on this topic, including additional examples and explanations, please visit https://599cd.com/Enabled.
Thanksgiving is supposed to be simple: cook a turkey, gather around the table, eat too much, and spend the rest of the day wondering why you thought a second helping of stuffing was a good idea. Of course, every family gathering has its own little adventures. Some people deal with awkward relatives, some deal with burned rolls, and some of us apparently wind up hosting the Fellowship of the Ring.
There is something about Thanksgiving that turns an ordinary kitchen into a full-scale command center. You are timing the turkey, watching the potatoes, trying not to forget the cranberry sauce, and answering questions from people who somehow think a meal for four should include breakfast, second breakfast, elevenses, luncheon, afternoon tea, dinner, and supper. If hobbits ever come to your house, plan accordingly.
The first rule of hosting a big Thanksgiving dinner is to accept that your original plan is probably doomed. You may begin with a nice quiet meal in mind, but then extra guests arrive, somebody volunteers to "help," the grocery list doubles in size, and suddenly you are making emergency runs for dinner rolls.
That is when it helps to remember that the kitchen does not need a wizard. It needs somebody who knows where the potatoes are, how to use the oven, and which cabinet contains the Tupperware. Magical assistance is overrated anyway. A wizard may be able to fight a Balrog, but can he open a modern refrigerator? Can he tell whether the turkey has reached a safe internal temperature? These are the real tests of wisdom.
Thanksgiving also teaches us that every guest has a role. Some people can make gravy. Some can mash potatoes. Some can carve the turkey. Some should be kept far away from sharp objects, battle axes, and the good kitchen table. And some people will quietly form an alliance with the dogs in an effort to locate unattended food.
If you have Labradors, you already know that a turkey dinner is not a meal to them. It is a military objective. You can tell them "you shall not pass" all day long, but they will eventually find another route around the table. Gandalf had enough trouble with the Balrog. He never had to defend a roast turkey from two determined hungry dogs.
There are always a few Thanksgiving moments that feel far more dramatic than they should. The oven display lights up, and someone thinks the kitchen is under attack. A little smoke appears, and suddenly the beacons are lit. You burn one package of rolls, and before you know it, people are calling for aid from neighboring kingdoms.
Then there are the family traditions that nobody can fully explain. Every household has its own version. Maybe it is a particular side dish that only one person knows how to make. Maybe it is an annual argument over who gets the last piece of pie. Maybe it is a fruitcake that has somehow survived longer than several civilizations and should probably be carried to Mount Doom for everyone else's safety.
For all the chaos, though, that is really the point. Thanksgiving is not about producing a flawless meal worthy of a cooking show. It is about gathering the people you care about, making room at the table, and sharing whatever you have. Sometimes that means turkey, stuffing, mashed potatoes, and pumpkin pie. Sometimes it means leftovers for four days because your guests apparently require seven meals per day.
It is also a good reminder to be thankful for the little things: the people who help clean up, the dogs who keep you entertained, the person who remembers to bring the wine, and the folks who are willing to sit around the table and laugh when everything does not go exactly as planned.
Whether you are celebrating Thanksgiving with family, friends, neighbors, coworkers, or a completely unexpected group of travelers from Middle-earth, I hope your day is filled with good food and good company. And if somebody asks what you are doing for Christmas before the dishes are even finished, it is perfectly acceptable to pretend to be asleep.
You can watch the embedded video for the full Thanksgiving tale, including the gravy, the hobbits, the dogs, and the unfortunate situation involving Gandalf and a bag of flour.
Does your order form show line items from every order? Check the Link Master Fields and Link Child Fields properties on the subform control. The field names don't have to match. In this example, OrderID on the main form matches the value of OrderNumber in the line items. Watch my Fast Tip to see where to set both properties.
For a complete step-by-step video tutorial on this topic, including additional examples and explanations, please visit https://599cd.com/LinkMasterFields.
If several people use the same Microsoft Access database, it is usually a good idea to make them sign in before they get anywhere near the main menu. A custom login form can identify the current application user, control which buttons and forms they see, track what they do, and keep everyone following the workflow you built instead of wandering around in tables like they are exploring Grand Moff Tarkin's file cabinet.
The important thing is to understand what kind of problem you are solving. A login form is excellent for controlling the normal Access application experience. It is not, by itself, a vault door protecting your backend data from someone who already has direct access to the database file. Build the login form first, make it useful, and then add the appropriate security layers based on how sensitive your data really is.
A practical multi-user login system starts with a simple user table. At a minimum, that table should contain a unique UserID, a unique username, and whatever information you need to verify the user's password. For a basic demonstration, you might have fields such as UserID, UserName, and UserPassword.
Make the username field indexed with No Duplicates. You do not want two people named "Kirk" in the login table unless you enjoy debugging why one Kirk is suddenly using the other Kirk's permissions. A unique username gives the application one clear record to find during login.
For a real multi-user database, split the application first. Put the shared tables in a backend database on the server or network share, and give each user a separate local copy of the frontend containing forms, reports, queries, VBA, and linked tables. Multiple people should not all be opening and using the same frontend file. That causes performance problems, corruption headaches, and general sadness.
The login form itself should be unbound. It does not need a record source because it is not editing user records directly. It simply needs a username text box, a password text box, a Login or Submit button, and a Cancel button.
Set the password box's Input Mask to Password so Access displays asterisks while the user types. This keeps someone standing behind the user from casually reading the password over their shoulder. Just remember that this is display masking, not encryption. The value is still whatever it is in the underlying control and, if stored as plaintext, in the table too.
Set the Login button as the form's default button. That way, pressing Enter after entering credentials performs the login without requiring the user to click the button. Likewise, set the Cancel button as the form's cancel button so Esc can intentionally exit the application. These are small usability details, but they make the form feel like a proper application login instead of something held together with duct tape and hope.
When the user clicks Login, the VBA code should first pull the username and password from the form controls into local variables. Trim off accidental leading or trailing spaces, and use Nz to convert Null values into empty strings. That prevents Null-related errors and lets you test whether both fields were filled in.
If either value is blank, stop the login attempt and tell the user what is missing. You can keep it simple with a general message, or you can be friendlier by telling them whether they forgot the username or password and moving the cursor to the appropriate field.
Next, use DLookup to find the matching user record. One approach is to look up the UserID using the entered username. If no matching user is found, the lookup returns Null, which you can convert to zero with Nz. A zero UserID then tells you that the username does not exist.
Once a valid user is found, retrieve the stored password for that UserID and compare it with the password entered on the form. If the values match, open the main menu form and close the login form. The full VBA implementation is shown in the embedded video, including the DLookup criteria syntax and the quotation marks that always seem to multiply when you build text criteria in VBA.
For a more secure user experience, you may not want to tell someone whether the username or password was wrong. Instead of separate messages such as "User Not Found" and "Invalid Password," you can simply display "Invalid Login." That gives an outsider less information to work with if they are trying to guess usernames.
Password comparisons in Access are often case-insensitive unless you deliberately make them case-sensitive. If you want uppercase and lowercase characters to matter, compare the entered password and stored password with a binary comparison, such as using StrComp with binary comparison. Whether that is necessary depends on your environment, but it is worth making a conscious decision instead of assuming Access will do it automatically.
A simple three-strikes rule is easy to add. Declare an Attempts variable at the form level, set it to zero when the form loads, and increment it after each failed login attempt. Once the user reaches your limit, close the application. You can also display how many attempts remain, although some developers prefer not to reveal that information.
Be careful where you increment the counter. A missing username or password is not necessarily the same thing as a failed authentication attempt. You may want to let users correct empty fields without burning one of their three chances. The important part is that bad credential attempts are counted consistently.
You should also make sure the user cannot simply close the login form and bypass it. If the login form is your application gateway, closing it normally should exit Access rather than reveal the rest of the application. The embedded walkthrough demonstrates how to handle startup behavior and ordinary form closure so LoginF is actually the front door, not merely a decorative welcome mat.
Once your form works, set it as the startup display form under File > Options > Current Database. When the database opens, the login form should appear before the main menu. If you previously used an AutoExec macro to open your main menu, adjust or remove that behavior so it does not open the main menu before the user has authenticated.
At this point, you have an application-level login system. That is useful. After a successful login, you can store the current UserID in a TempVar or another application-level variable. Then your forms can decide what that user is allowed to do.
For example, a salesperson might be allowed to add and edit customers but not delete them. A manager might see an administrative menu that regular employees never see. An accounting user might be able to run financial reports, while a front-desk user sees only customer and order screens. This kind of interface control prevents many ordinary mistakes and keeps users focused on the jobs they are supposed to perform.
You can also use the current user information for activity tracking. Add CreatedBy and ModifiedBy fields to important tables, record login and logout times, or maintain an activity history table. When someone changes a shipping address right before the customer calls to complain, it is helpful to know who made the change and when.
Now for the important disclaimer: a custom Access login form does not independently secure the backend data file. It tells your application who the user claims to be, and it can control what the application allows that user to see or do. But if someone can directly open the backend database, import its tables, or otherwise access the data outside your frontend, your login form does not magically stop them.
Think of it like a backyard fence. It establishes a boundary, keeps honest people from wandering where they should not go, and stops a lot of casual nonsense. But a determined burglar can climb a fence. For a trusted small office, that fence may be exactly what you need. For confidential payroll, medical information, financial records, or other sensitive data, you need stronger layers.
One useful frontend layer is to hide the Navigation Pane, restrict the Ribbon and shortcut menus where appropriate, disable design access for ordinary users, and distribute an ACCDE file instead of your editable ACCDB master. An ACCDE compiles your VBA and prevents routine users from opening your code as editable source or changing form and report designs.
However, ACCDE is not encryption. It does not make every table invisible, encrypt your stored values, or create real per-user permissions. Keep your original ACCDB safe, because that is your editable development copy. Distribute ACCDE copies to users when it makes sense, but do not confuse compiled deployment with data security.
If you need to protect an entire Access file from being opened without authorization, consider Access database encryption with a database password. This protects the file itself. It is different from the individual usernames in your custom login table because it is generally one shared password for the database file.
That means Kirk and Picard may have separate application logins, but they can still ultimately connect to the same backend using the same shared backend password. The backend does not automatically understand your custom Access username. It knows whether the connection has the credentials necessary to open the file.
For departmental separation, separate backend files can help. For example, sales data can live in one backend while confidential accounting or payroll data lives in another. But simply leaving the accounting tables unlinked in the sales frontend is not security. If a sales employee can browse to and open the accounting backend directly, the missing link did not accomplish much.
The real enforcement in that situation comes from Windows file and folder permissions. Properly configured share permissions and NTFS permissions can prevent unauthorized Windows accounts from opening restricted backend files in the first place. Authorized Access users also need enough permissions to create and update the Access lock file, so test your setup using real authorized and unauthorized accounts. Do not solve this by giving Everyone Full Control. That is like fixing a squeaky door by removing the wall.
Another technique is dynamic table linking. Instead of permanently distributing links to all backend tables, the frontend can validate the application login and create required links programmatically. It can remove those links again during a normal exit. This is useful hardening, but it is still not independently enforced authorization. The frontend still has to know how to connect to the backend, and a determined person with enough access may be able to recover that information.
Also, do not store production passwords as readable plaintext the way a simple demonstration table does. Plaintext passwords are easy to understand in a beginner example, but anyone who can read the table can read the passwords. A proper production authentication system should use salted password hashing so the original password does not need to be stored or recovered.
Hashing is not the same thing as encryption. Encryption is designed to be reversible with the correct key. Password hashing is designed for verification: hash what the user entered and compare it to the stored hash. And please do not use real Windows, email, banking, or other important passwords in a practice database. That should not need to be said, but here we are.
You may also see old Access tutorials discussing workgroup files, users, groups, and object-level permissions in MDB databases. That was the old workgroup-based user-level security model. Modern ACCDB and ACCDE files do not support it. Building a UserT table and LoginF form gives you useful application identity and application rules, but it does not restore the old MDB security system.
When you need independently enforced permissions inside the same shared dataset, especially for sensitive data, SQL Server is usually the better backend. Access can remain the frontend, so users can keep using familiar Access forms, reports, queries, and VBA. The difference is that SQL Server can authenticate the connection and decide whether a request is actually allowed.
Of course, moving tables to SQL Server does not automatically solve everything either. If every frontend connects using the same all-powerful SQL Server account, then SQL Server sees everyone as that same account. Meaningful per-user restrictions require proper authentication, carefully managed permissions, and least-privilege design. Give people access to what they need, not the keys to the entire building because one person needs the break room.
A custom Access login is still a very worthwhile tool. It can provide a cleaner application experience, guide users into the right workflow, control forms and buttons, personalize screens, and support useful audit tracking. Just be honest about what it is: an application gate, not a complete security architecture.
Build the login form, test blank entries, invalid users, wrong passwords, case sensitivity, successful login, Cancel, ordinary form closure, and the failed-attempt limit. Then decide what additional layers your particular business needs: frontend restrictions, ACCDE deployment, database encryption, Windows permissions, separate backend files, or SQL Server.
The full embedded video walks through building and testing the form in Access, including the VBA logic behind the login button and the startup configuration. Use the right tool for the job, and your Access application will be a lot more polished, manageable, and difficult to misuse accidentally.
If blank notes leave holes in your printed report, check Can Shrink in two places: the Notes text box and the Detail section. If there's a label beside the box, move it out of that row or remove it. In this video, I'll show you how to set it up and check the result in Print Preview.
For a complete step-by-step video tutorial on this topic, including additional examples and explanations, please visit https://599cd.com/1641.
Time for a quick VBA random-number quiz. If you work with quizzes, dice rolls, random record selection, games, sample data, or anything else where Access needs to make a somewhat unpredictable choice, you need to understand what Rnd, Randomize, and Int are actually doing. Otherwise, your dragon's hoard may contain fractional gems, and nobody wants that.
Try the five questions below before reading the answers. Keep score if you like. You have all the time you need here, unlike the video quiz where you only get a few seconds before the answer shows up.
Question 1: What range of values does the VBA Rnd function normally return?
A. Whole numbers from 0 through 1 B. A value greater than or equal to 0 and less than 1 C. Whole numbers from 1 through 10 D. A value from negative 1 through positive 1
Answer: B. VBA's Rnd function returns a fractional number that is greater than or equal to 0 and less than 1. In other words, it can return 0, 0.25, 0.9999, and plenty of values in between, but it will not normally return 1.
This is one of the most important things to remember about Rnd: it does not give you a random whole number by itself. You have to scale it into the range you want and then convert it to an integer.
Question 2: Why would a VBA programmer use a Const declaration instead of a normal variable for a maximum quiz value?
A. It automatically stores the value in a table B. It lets the user change the value while the form is open C. It gives a fixed named value that code should not change D. It makes the value available to every procedure automatically
Answer: C. A constant gives you a fixed, named value that your code should not change. If your quiz has a maximum question number, maximum die value, or maximum treasure count, using a clearly named constant makes the code easier to read and maintain.
Instead of scattering the number 6 all over your code because you are rolling a die, you can define a meaningful value such as MaxValue. If the range changes later, you update it in one place instead of hunting down every mystery 6 in the database. Future You will appreciate that.
Question 3: What is the main purpose of calling Randomize before generating values with Rnd?
A. It seeds the random-number generator so sequences can vary between runs B. It converts Rnd results directly into whole numbers C. It guarantees that no generated value will ever repeat D. It resets every variable on the current form
Answer: A.Randomize initializes, or seeds, VBA's pseudo-random number generator. Without it, your application may begin with the same sequence of supposedly random values each time it runs.
Random numbers generated by VBA are technically pseudo-random. The computer follows a mathematical sequence. Calling Randomize, usually once when your application starts or before you begin a random operation, helps ensure that separate runs do not keep starting from the same point in that sequence.
It is important to understand that Randomize does not guarantee that values will never repeat. A die can roll a 4 twice in a row. That is normal. Random does not mean every result must be different. It means the results are produced in a way that is not predictably patterned for your user.
Question 4: For a positive decimal value such as 8.8, what value does VBA return from Int(8.8)?
A. 8.8 B. 9 C. 0 D. 8
Answer: D.Int(8.8) returns 8. The Int function returns the integer at or below the supplied number. With positive values, that effectively removes the decimal portion.
This is why Int is so useful with random-number generation. Once you have a decimal value from Rnd, you can scale it up to your desired range and use Int to turn it into a usable whole number.
One small detail that catches people: Int rounds down, not toward zero. For positive numbers, those ideas look the same. For negative values, they do not. For example, Int(-8.8) gives you -9. Fortunately, most simple random-range examples are working with positive numbers.
Question 5: Which expression correctly generates a whole number from 1 through MaxValue when MaxValue is a positive integer?
A. Int(Rnd) * MaxValue + 1 B. Int(Rnd * MaxValue + 1) C. Int(Rnd * MaxValue) + 2 D. Rnd / MaxValue + 1
Answer: B. The expression is Int(Rnd * MaxValue + 1).
Here is the basic idea. Rnd gives you a value from 0 up to, but not including, 1. Multiplying by MaxValue stretches that result into a range from 0 up to, but not including, MaxValue. Adding 1 shifts the range upward. Then Int removes the fraction, leaving a whole number from 1 through MaxValue.
For a standard die roll, set MaxValue to 6. The result will be an integer from 1 through 6. You will never get 0, and you will never get 7. That is exactly what you want unless you are playing some kind of very suspicious seven-sided dragon dice game.
The common mistake is putting the parentheses in the wrong place. For example, Int(Rnd) * MaxValue + 1 is not correct because Rnd is always less than 1. Applying Int to it first turns it into 0, which means the result is always 1. That is less "random number generator" and more "a button that always says 1."
If you got all five correct, congratulations, you are keeping accurate inventory of the hoard. If you missed a couple, no worries. Randomization is one of those little VBA topics that becomes easy once you understand the order of operations: seed the generator, get the fractional random value, scale it, shift it if necessary, and convert it to an integer.
Watch the embedded video for the quiz version and a quick review of these concepts. The full details of VBA random number generation are covered in Microsoft Access Developer Level 3, Lesson 2.
An order shouldn't point to a customer who doesn't exist. In the Relationships window, turn on Enforce Referential Integrity between your customer and order tables. Access will block an order with a CustomerID that isn't in the customer table. Watch the video to see how to set it up and why Cascade Delete deserves a second look.
For a complete step-by-step video tutorial on this topic, including additional examples and explanations, please visit https://599cd.com/2275.