Transform part of an identification number into text VBA access - ms-access

Can someone help me with a little problem. In summary I have a db where you input someones personal details and I have 4 fields I would like VBA to generate automatically. First field is an ID Number field then following that is DateOfBirth and Age fields. They are auto generated from just the ID field. However, to save me time, I want a part of the ID number field to generate whether a person is male or female.
To explain this let me set an example. The ID number is based on South African identification number. It's a 13 digit number e.g. 851205 5205 08 6. The first 6 numbers tells the date of birth (1985/12/05). That part of the number updates my DOB field and then also tells me the persons age with more VBA. Now i want the numbers "5205" to auto generate my gender field whether a person is male or female. Females are assigned numbers in the range 0000-4999 and males from 5000-9999. If you like more detail then please Google 'decoding your South African ID Number'.
So if i should type in that ID number above then it will define the person as a male. Can anyone help me with some VBA?
Thank you
found a solution and it works just the way i want it to:
If (Mid([txtIDnumber].Value, 7, 4) > 4999) Then
Me.cboGender = "MALE"
Else
Me.cboGender = "FEMALE"
End If

Related

Creating relational Tables in Ms Access

I have to change my first question to the following:
I have 3 tables:
Clients,
Gender,
Race
Clients:
ClientID long integer
GenderID long integer
Gender short text
RaceID long integer
Race short text
Gender:
GenderID long integer
Gender short text
Race:
RaceID long integer
Race short text
What should I do in order to be able to modify data in the main table Clients -so they'd be changed according to content in Race / Gender tables
For example:
Gender table:
GenderID Description
1 Male
2 Female
Clients table:
ClientID GenderID Gender DOB
11 2 Female 1/1/1977
12 2 Female 1/2/1970
13 1 Male 1/4/1969
So, if I'd modify for example, ClientID "13" Gender to "Female" instead of the current one "Male", so that the GenderID would be automatically changed to "2"?
(And no other number would be allowed for that GenderID)
Or - if I'd modify ClientID from 1 to 2, I want the Gender to be changed to "Female"
Thank you, again
You should not use both a character-field, Race, and a foreign-key field, RaceID, in your schema design: you should only use the latter, RaceID.
You shouldn't, and-d-d-d, you don't need to.
Your reports and so forth would then be based upon a query which JOINs to all three tables – displaying the Race.Race value ("White") but never the (meaningless ...) RaceID integer.
Your input-fields would be combo-boxes which query (say) the Race table to find possible values, binding on the RaceID field.
The Clients table contains foreign-key numbers which the end-user never actually sees. Queries (and combo-box parameters) are used to reference the corresponding strings.
You should also use Referential Integrity constraints to ensure that Clients.RaceID, if it is not NULL, must be a value in the Race table.

format number in specific currency based on another column data

In SSRS
I have a table with column person, column country, and column salary. I want the column salary in a specific currency format based on column country. For example, if column country is United States, corresponding salary should be displayed in $.
Similarly, if the country column shows India, then the salary column should show a rupee, etc.
I am a starter and unable to do this. Please tell me a simple way of doing this
You could return a second dataset with a list of Countries and their Currency symbols such as
Country Currency
USA USD
India RUP
UK GBP
Then you can use LOOKUP to 'look up' the value in the second datasset from the first, so a dataset of
Country Sales
India 404
UK 44
USA 1255
You can then used the lookup as follows
=Lookup(Fields!Country.Value,
Fields!Country.Value,
Fields!Currency.Value,
"DataSetCurrency") <--- Blue <Expr> in the example below
Remember, you can include more than one Placeholder (expression) in a cell, so a design like this
Would render as this (DataSetCurrency included for information only)
Hopefully this will answer your question, though please ask for clarification if required.

DB table creation -- breaking down age groups

I have a tutoring website where teachers list their preferences for the ages of their potential students.
So far, I have broken those ages into the following categories:
0-4, 5-9, 10-14, 15-19, Adults. These categories, I think, represent decent break points for students ages. But no matter -- the real issue is table creation.
I will make a secondary table, teachers_ages, with a foreign key for teacher_id and another column for age. Should I make this column an enum, with the following acceptable choices '0-4' '5-9', '10-14', '15-19', 'Adults'?. Is this somehow bad-practice (to group numbers with words?) Does it violate any database creation norms? Is there a better way to break age groups for use with CRUD?
Update: teachers can choose as many age groups as they want
Typically you would create a lookup table which would list an identifier and the associated value. For example
Lookup table (AgeRange)
ID Min_Age Max_Age Description
1 0 4 "Less than 4"
2 5 9 "5 to 9"
3 10 14 "10 to 14"
4 15 19 "15 to 19"
5 20 1000 "Adults"
Now you can add another table with the teacher id and the age range id. (There can be more than one entry in this table allowing teachers to have any number of preferences.)
When validating you join to this table and look at Min_Age and Max_Age. When reporting you use the Description field.
If each teacher can only choose one age group you do not need to add a second table. Put the age-group field in the teacher table. Set the datatype as varchar and use check constraints for your five choices.
Your approach is a valid way to break groups down into demographics, such as age, income, population, etc.

Need to split delimited string into seperate rows in ms-access Sub form

I have a form in MS-Access which shows tabular data. as follows
record id record date record content
--------- ----------- --------------
1 1/2/2011 name: ben, age:38, sex: M; name: emma, age:32, sex: F
2 5/5/2012 name: john, age:28, sex: M; name: eva, age:24, sex: F
There is no limit in how many people's records can be there in each record content cell. but each record will have only those 3 fields. Name, Age and Sex.
I need to split the record content in a subform such a way that it looks like:
record id record date record content
--------- ----------- --------------
1 1/2/2011 name age sex
---- --- ---
ben 38 M
emma 32 F
2 5/5/2012 name age sex
---- --- ---
john 28 M
Eva 24 F
What is the easiest way to achieve this? The table from where the record is coming has the data in similar format as shown in the first diagram. How can I split this compound string and display it in multiple rows?
You need to normalise your data--split the source table up into two.
(How? You need to write some VBA code to:
read each row of your records table
save the value of the [record id] column into a variable you will use later in this loop
for each value of the [record content] column, get the value into a string
split the string using the delimiter ";". That is, semi-colon. Use the split() function. See Split strings in excel (vba) for an example. You will get back a list of strings. Each string in the list will be like this: "name: xyz, age: xyz, sex: xyz"
extract your data from this string using a regular expression. See http://mark.biek.org/blog/2009/01/regular-expressions-in-vba/ for an example in Access.
this regular expression will probably get you the name, age and sex out of the string as the first, second and third matched items:
"^.*name:\s*([^,]+),\s*age:\s*([^,]+),\s*sex:\s*([.*])$"
after doing the regex match you grab the matched items, put them into name, age and sex variables, and use these values and the record id you saved earlier to insert into the new People table.)
Tables:
People
ID
RecordID - references Records.ID
PersonName
Age
Sex
Records
ID
RecordDate
After that you can use a sub-form within your current main form to display the people associated with each record. Access makes that pretty easy if you have a parent-child relationship between two tables, as you do above.

Microsoft Access 2010 - Filtering by a caculated field in a query-based report

Ok, here's the condensed form. I have three main tables to draw data from:
StudentData - PK is the student's ID Number. Contains contact info, their current status ('00' for none, 'P' for Probation, 'S' for Suspension), and cumulative gpa data.
CourseData - PK is the CRN. Contains just the abbreviated subject and the course number (IE ECON 200)
StudentCourses - PK is an AutoNum. Many-to-Many relationship table between StudentData and CourseData. Also contains stats for the particular student's class (grade, credit hours, etc).
So some sample data would look like:
-
StudentData
ID: 12345678
Name: John Doe; ...[Other contact info]; 00; CumCreditHours: 100; CumCoursePoints: 190
-
CourseData
CRN: 0001; Abbrev: ECON; CourseNumber: 101
CRN: 0002; Abbrev: CSCI; CourseNumber 201
-
StudentCourses
AutoNum: 1
StudentID: 12345678; CRN: 0001; Grade: A-; Credits: 3
AutoNum: 2
StudentID 12345678; CRN: 0002; Grade: B; Credits: 3
-
At this point, this is how I have things set up:
First, a query runs that finds all of the courses a student takes and converts the letter grades into a point value. Another query based on the first sums the point totals and the credit hours. A third query takes those totals and calculates the GPA by dividing their point total by the credit hour total.
Separately, a query runs that calculates the student's cumulative GPA by taking their cumulative points and hours from the StudentData table (again dividing the points by the hours).
Then, another query takes both the semester GPA, cumulative GPA, current status, and cumulative credit hours and calculates the recommended action for the student. So for our example data it would look like:
_
SemesterGPA: 3.33; CumulativeGPA: 1.90; CurrentStatus: 00; CumulativeCreditHours: 100
_
I have the formula to determine their recommended action set up as a series of nested IIF statements that looks like:
IIf([CurrentStatus]="00" And [CumulativeGPA]<2 And [CumulativeCreditHours]>=12 And [CumulativeCreditHours]<=23,"PFY",IIf([CurrentStatus]="00" And [CumulativeGPA]>=1.7 And [CumulativeGPA]<=1.99 And [CumulativeCreditHours]>=24,"P",IIf([CurrentStatus]="00 " And [CumulativeGPA]<2 And [SemesterGPA]<2 And [CumulativeCreditHours]<12,"W",IIf([CurrentStatus]="00" And [CumulativeGPA]>=2 And [CumulativeGPA]<=2.5 And [SemesterGPA]<2 And [CumulativeCreditHours]>=12,"WUP",IIf([CurrentStatus]="00" And [CumulativeGPA]<1.7 And [CumulativeCreditHours]>=24,"SUSP",IIf([CurrentStatus]="P" And [CumulativeGPA]<2 And [SemesterGPA]>=2 And [CumulativeCreditHours]>=12,"CP",IIf([CurrentStatus]="P" And [CumulativeGPA]>=2 And [SemesterGPA]<2 And [CumulativeCreditHours]>=12,"SPCP",IIf([CurrentStatus]="P" And [CumulativeGPA]>=2 And [CumulativeCreditHours]>=12,"RP",IIf([CurrentStatus]="P" And [CumulativeGPA]<2 And [SemesterGPA]<2 And [CumulativeCreditHours]>=12,IIf(IsNull([PriorSuspension]),"S(FD)","D(SD)"),"None")))))))))
For our example, John Doe's recommended action would be 'P' since his current status is 00, he has over 24 cumulative credits, and his cumulative gpa is between 1.7 and 1.99.
Now for the problem: I would like to be able to make a report that can filter by the recommended action. I've detailed the issues I've had previously, but in short, the way I have the reports set up now (with the information being displayed in a sub-report inside a report that is based on the StudentData table to provide the aforementioned queries with the StudentID) doesn't allow me to do this because the field I want to filter by exists in the sub-report and not the main report (and you can't set the filter properties for a sub-report).
Any ideas?
Ok, I've got this to work now. I realized that as I was calculating the semester GPAs that I had grouped the results together by ID at some point during the process. This allowed me to remove the part of the initial query that grabbed the ID number from the form. Since the last query in the process linked everything together by student ID, the individual records held all of the information I needed and everything fell into place after that.
I half expected something simple like this to be the answer to my problem, but I'm still disappointed that it took me this long to figure it out...
Anyway, thanks to anyone who might have been thinking of possible solutions for this problem.