Database entry on forms screen

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Need to track customers and their appointments using phone number as the
primary key. Basically, I want the user to input a phone number, if a
corresponding record already exists, then the name/address fields will
automatically populate; if not, the user is prompted to enter corresponding
data. I have the appointments table linked and it is working fine and am
able to establish as a "subform" on my forms entry screen. Additional
problem is that if there is more than one customer with the same ph# then I
can't use "no duplicates" but then how will I be able to use as a search
criteria? Oh woe is me. . . .
 
Customer table:
CustomerID AutoNumber primary key
Surname Text
FirstName Text
Phone Text
...

Appointment table:
AppointID AutoNumber primary key
CusomterID Number foreign key to
Customer.CustomerID
StaffID Number who the appointment is
with.
AppointDateTime Date/Time when the appointment is.
AppointNote Memo what the appointment is about.

Staff table:
StaffID AutoNumber primary key
Surname Text
FirstName Text
...

Main form bound to Staff table, with subform to show the appointments for
the staff member. For the subform, create a query that uses the Customer
table and the Appointment table. You can filter the subform to those entries
that match a particular phone number.

For the form where you enter new customers, you can use the BeforeUpdate
event of the Phone field to warn the user if this is a duplicate, but let
them enter the record anyway.
Private Sub Phone_BeforeUpdate(Cancel As Integer)
Dim strWhere As String
Dim varResult As Variant
Dim strMsg As String

If IsNull(Me.Phone) Or (Me.Phone = Me.Phone.OldValue) Then
'do nothing
Else
strWhere = "[Phone] = """ & Me.Phone & """"
varResult = DLookup("CustomerID", "Customer", strWhere)
If Not IsNull(varResult) Then
strMsg = "Phone number exists for Customer " & varResult & _
vbCrLf & "Continue anyway?"
If MsgBox(strMsg, vbYesNo+vbDefaultButton2) <> vbYes Then
Cancel = True
End If
End If
End If
End Sub
 
Thanks Allen for the reply.

This info was a good start in assisting with my table relationships but
doesn't exactly fit my scenario. I didn't provide enough clarification
trying to keep my post short; however. . .
I'm actually trying to setup a database of Customers (who are passengers on
a bus). As explained before, in order to not duplicate customers we want to
use the phone number as a "unique" identifier. (However, there will be times
when someone in the same household is a unique customer as well.) I
established this table as:

CustomerName:
Address: (which will be a mailing address and always a PO Box)
City: (I have a limited number of entries that will be
utilized)
ZipCode: (I would like to have this data automatically filled in
AND STORED in the customer table) from a lookup from another table (which I
get to work on the form but it doesn't enter the data into the table
Phone:
Date of Suspension:
Date of Reinstatement: (would like this to calculate 30 days after the date
of suspension)

I have created second table called Appointments -- consisting of:

Phone:
Date:
Time:
Cancelled: (as a yes/no checkbox)
Reason: (lookup list)

I have created a relationship between the two based on the phone number
fields (also made the phone number the primary key in the Customer table).

I made a form with the appointments as a subform. Any existing data and
corresponding appointments display IF the two tables already have data
entered. I can input a new record for each table IF the phone number is
unique. However, IF I display each record and type into any field, it just
changes the data and then I get an error if I've duplicated the phone number.

I'd also like the form screen to start with a "new record" or blank rather
than record #1 of the customer table.

I'd probably figure this out eventually but why bang my head against the wall.

After data is entered into the tables, we will be running reports to pull
anyone with three cancellations that have a reason greater than 1 and I think
I can handle that one. The hard part is getting the data into the form and
from the form to the tables.

Again, thanks, thanks, thanks!
 
Answers embedded.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Perplexed said:
Thanks Allen for the reply.

This info was a good start in assisting with my table relationships but
doesn't exactly fit my scenario. I didn't provide enough clarification
trying to keep my post short; however. . .
I'm actually trying to setup a database of Customers (who are passengers
on
a bus). As explained before, in order to not duplicate customers we want
to
use the phone number as a "unique" identifier. (However, there will be
times
when someone in the same household is a unique customer as well.) I
established this table as:

CustomerName:
Address: (which will be a mailing address and always a PO Box)
City: (I have a limited number of entries that will be
utilized)
ZipCode: (I would like to have this data automatically filled in
AND STORED in the customer table) from a lookup from another table (which
I
get to work on the form but it doesn't enter the data into the table
Phone:
Date of Suspension:
Date of Reinstatement: (would like this to calculate 30 days after the
date
of suspension)


Add a CustomerID (AutoNumber) field. Primary key.
You cannot use Phone as primary key, because it is not unique.

Regarding whether to store the date of reinstatement and how to do that,
see:
Calculated fields
at:
http://members.iinet.net.au/~allenbrowne/casu-14.html

Use the AfterUpdate event of City to lookup the zip code. Use DLookup().
Details in:
Getting a value from a table: DLookup()
at:
http://members.iinet.net.au/~allenbrowne/casu-07.html

BTW, we usually split the CustomerName into 2 fields (first name and
surname). Searches, filters, and sorting are more powerful and efficient
that way.

I have created second table called Appointments -- consisting of:

Phone:
Date:
Time:
Cancelled: (as a yes/no checkbox)
Reason: (lookup list)

I have created a relationship between the two based on the phone number
fields (also made the phone number the primary key in the Customer table).


The relationship based on phone number is no good. It does not uniquely
identify the customer. Remove the Phone field from the Appointments table,
and replace it with CustomerID (Number), so you have a relationship that
uniquely identifies the person.

Even the name + phone number is not unique: it's not unusual to have a
father and son with the same name, at the same address, with the same phone
number.

After doing that, open the Relationships window (Tools menu), and create a
relationship between the two tables based on CustomerID. Check the box for
referential integrity.

In your form, you can use a combo box to *display* the phone number, but
store the CustomerID. Give the combo these properties:
Control Source CustomerID
Row Source SELECT CustomerID, Phone, CustomerName
FROM Customers ORDER BY Phone;
Bound Column 1
Column Count 3
Column Widths 0;1;0
Because the CustomerID column is zero-width, Access will display the next
column.

I made a form with the appointments as a subform. Any existing data and
corresponding appointments display IF the two tables already have data
entered. I can input a new record for each table IF the phone number is
unique. However, IF I display each record and type into any field, it
just
changes the data and then I get an error if I've duplicated the phone
number.

I'd also like the form screen to start with a "new record" or blank rather
than record #1 of the customer table.


To open the Appointment for to a new record, set its Data Entry property to
Yes. Alternatively (if you want the old data to be available also), add this
to the Load event procedure of the form:
Private Sub Form_Load()
If Not Me.NewRecord Then
RunCommand acCmdRecordsGotoNew
End If
End Sub

You need to distinguish between *finding* data and *entering* data. Don't
try to use the same text boxes for both. Typically what we do is to add some
unbound boxes to the Form Header section (View menu when in form design),
and make the a different color (yellow) so it is really obvious to the user
that these are for navigation and the white ones in the detail section are
for editing.

There is an example of how use an unbound combo in this link:
Using a Combo Box to Find Records
at:
http://members.iinet.net.au/~allenbrowne/ser-03.html
This combo could display and by sorted by phone number if you wish (like the
example given above).

You mentioned you have a subform for Appointments? You could even put the
combo's name into the LinkMasterFields property of the subform control, and
CustomerID into the LinkChildFields. Access will then just show the
appointments for the customer in the combo, no code needed.
 
Thanks so much Allen for all the advice and examples!!! You're a great
resource and as soon as I can implement the changes to my database I'll let
you know how it works out.

Happy Holidays from Big Bear California where it is only 29 degrees today!

BettyAnn (no longer so perplexed ha ha)
 
Back
Top