Create a Random Name Generator in Microsoft Access VBA

Create a Random Name Generator in Microsoft Access VBA

Table of Contents

  1. Introduction
  2. Building a Random Name Generator
    1. Jumbler
    2. Completely Random Names
  3. Prerequisites
  4. Building the Queries
    1. Random First Name Query
    2. Random Last Name Query
  5. Building the Randomizer
    1. Jumbling First and Last Name
    2. Capitalizing the First Letter
    3. Adding a Sleep Timer
  6. Building the Random Name Generator
    1. Determining Name Length
    2. Checking If Name Starts with a Vowel
    3. Generating Random Characters
    4. Capitalizing the First Letter
    5. Randomizing Vowels and Consonants
    6. Selecting a Random Letter
  7. Customizing Name Length
  8. Conclusion

Introduction

Welcome to another fast tips video brought to You by accesslearningzone.com. In this video, we will be building a random name generator. We will Create two different types of generators: a jumbler and a generator that creates completely random names. This exercise will not only be fun but will also provide some VBA practice.

Building a Random Name Generator

Jumbler

The first generator we will build is a jumbler. It combines a list of first names and last names to create random name pairs. For example, "John Peart" or "Deanna Reese Davies". This is useful for creating fictional names or for team building exercises.

Completely Random Names

The Second generator will create completely random names using random sequences of characters. This is ideal for fantasy novelists, DND players in need of character names, or even pharmaceutical companies looking for unique drug names.

Prerequisites

Before we get started, there are a few prerequisites you should be familiar with:

  1. Intro to VBA: This 20-minute video will teach you everything you need to know about programming in VBA.
  2. Random Records: Learn how to generate random numbers and return random records with this video.
  3. Coin Toss: This video explains how to simulate a coin toss using VBA.
  4. Sleep: Watch this video to learn how to incorporate a sleep timer into your code.

Make sure to watch these prerequisite videos to gain a better understanding of the concepts we'll be covering.

Building the Queries

To generate random names, we need to build two queries: one to select a random first name and another to select a random last name. Since some names might be missing from either list, we'll create two separate queries to account for this.

Random First Name Query

Create a query with the following criteria:

  • Base it on the "Customer T" table.
  • Include the "Customer ID" field, "First Name" field, and a calculated field for a random number.
  • Set the criteria for the "First Name" field to "Is Not Null".
  • Sort the random number in ascending order.
  • Set the query to return only one Record.

Random Last Name Query

Create a similar query for the last names with the following criteria:

  • Base it on the "Customer T" table.
  • Include the "Customer ID" field, "Last Name" field, and a calculated field for a random number.
  • Set the criteria for the "Last Name" field to "Is Not Null".
  • Sort the random number in ascending order.
  • Set the query to return only one record.

Building the Randomizer

Now we can start building the random name generator using VBA code.

Jumbling First and Last Name

First, we'll create a function that jumbles the first and last names together. This function will take in a first name and a last name, and return a jumbled name pair. The function will also capitalize the first letter of each name for a more aesthetically pleasing result.

Capitalizing the First Letter

To ensure that the first letter of each name is capitalized, we'll add a condition to the code. If the length of the name is zero (meaning it's the beginning of a new name), we'll capitalize the first letter. Otherwise, we'll leave it as lowercase.

Adding a Sleep Timer

To prevent the random number generator from producing the same sequence of numbers, we'll add a small sleep timer between each iteration of the loop. This will ensure a more randomized result.

Building the Random Name Generator

To generate the random names, we'll create a function that determines the length of the name and whether it should start with a vowel or consonant. The function will then loop through the process of selecting random characters until the desired name length is reached.

Determining Name Length

First, we'll determine the length of the name using a random number between the specified minimum and maximum lengths. This will ensure variable name lengths.

Checking If Name Starts with a Vowel

Next, we'll determine whether the name should start with a vowel or not using a coin toss function. This will provide a 50/50 chance of starting with a vowel.

Generating Random Characters

For each iteration of the loop, we'll select a random character from either the vowel or consonant queries. This will create a mix of vowel and consonant characters.

Capitalizing the First Letter

To ensure the first letter is capitalized, we'll add a condition that capitalizes it if it's the start of a new name. This will improve readability and presentation of the random names.

Randomizing Vowels and Consonants

To create a more random result, we'll flip the condition for selecting either a vowel or consonant after each iteration of the loop. This will ensure an equal distribution of vowels and consonants.

Selecting a Random Letter

Finally, we'll select a random letter from the vowel or consonant queries and append it to the name. We'll Continue this process until the desired name length is reached.

Customizing Name Length

If you want to customize the minimum and maximum length of the generated names, you can pass these values as parameters when calling the function. This allows for more flexibility and control over the generated names.

Conclusion

In this video, we've built a random name generator that can create both jumbled and completely random names. This generator can be used for various purposes, such as character names in novels, fantasy games, or even generating unique drug names for pharmaceutical companies. The code provided is scalable and can be customized to fit specific requirements. Have fun experimenting with different settings and enjoy the endless possibilities of the random name generator.

Find AI tools in Toolify

Join TOOLIFY to find the ai tools

Get started

Sign Up
App rating
4.9
AI Tools
20k+
Trusted Users
5000+
No complicated
No difficulty
Free forever
Browse More Content