form design question start over

G

George Applegate

I have an access data base with two files:

Transactions
Customers

Customers has a location code in it. THe transaction file links to
the customer file with customer number.

I have created a query which combines the two files and shows customer
name and department number along with transaction file information..

Now I want to create a form for each location to enter transactions.
But I only want form xx to be able to enter transactions for customers
with location code XX. I think I need to enter a "validation rule",
ON THE FORM, but can anyone help me do that? I created a form from
the query, but I don't get how to not allow any transactions be
entered for customers who aren't assigned to that location.

If I enter customer 3800, and press enter in the form, it brings in
location YY and customer name. Problem is, I only want location XX to
be valid on this form. How can I do this? I think I should be able
to create a validation rule on the form that restricts someone from
entering a transaction for a customer that isn't their location???

Not sure I totally understand this. Or is there a better way someone
could point me in the right direction or give me an example of?

Any help or suggestions would be greatly appreciated.

Thanks,
ga

George Applegate
(e-mail address removed)
 
A

Albert D. Kallal

An interesting suggestion here is to have your actual database design force
you to follow your user interface design.
Now I want to create a form for each location to enter transactions.

does that mean you want to search setup and display a form with a particular
location, and then enter customers into that location?

OK now you talking about bringing up a customer on display, and then entry
transactions for the customer???

you gonna have to decide how you work flow and how your work is going to
court here.

Furthermore what's to stop a person from entering any location out of the
blue? (I notice you ask that question also).

You have to decide how your user interface is going to operate here.

You either

a) search find and display a particular location, and then that location
form will display all the possible customers for that given location

b) search find and display a customer, and then have some type of ability to
select an assigned that customer to a particular given location

c) you want both of the above capabilities.

It seems to that the first thing I would do is build and design a table of
locations. all the information about that location such as where it is in
the city, perhaps who maintains that location, perhaps whatever information
you want about that location, you build a table with all the fields that the
finds that location place. There also might be some kind of location code
also, and include that in the table also.

At this point you're going to have to edit each of the customers now, and
set their location field. It is assumed that this location field will simply
be (store) te ID field that points to the primkary key (id) field of the
table locatons. This also make your application more user friendly, since
for each customer form that you bring up and display, you'll have a nice
combo box that only allows you to assign that customer to one location. Note
while the combo box can (will) store the primary key of id from the
locations table, the combo boxes are designed to display and search by a
descriptive text type field from the locations table (the beauty of this is
thus you can distort the primary key ID in this field from locations, but it
will display the text field, or even perhaps your external location code
that you and your users are used to now.).

at this point than you can build locations form, and the user can search
find that equivocation they want to work on, and the list of customers that
belong to that location who can thus be displayed as a sub form.

when you bring up the customers form, for each customer you can have a sub
form and your table of transactions. there's no need in your table of
transaction to set the location code, because each transaction is related to
customers, and the customers has the location code already set. Dolby no
possibility of a air and shrink the wrong location code into transactions,
because you in fact never actually enter location code into transactions
because you don't have to. the location code and transaction is set by the
mere fact of transactions being attached to a particular customer.

The above a course assumes that one customer can only be in one location,
and if that rules not the case then you'll have to change your designs to
accommodate this issue, but you're not yet alluded to this issue yet.

So, we have

locations-->
customers--->
tranactions
 
G

George Applegate

Albert,

I am not looking for anything fancy here. I appreciate your questions
and ideas. The customer information (customer number, name, address,
and LOCATION) are already loaded and no one wll actually enter those.

The transaction form has a "customer #" field on it; when I enter
that, into the form automatically comes the LOCATION, name, address,
etc.

What I want to do though is, if it is my LOCATION XX query, when they
enter a customer number, if that customer number isn't assigned to
their location (XX), I don't want them to be able to enter a
transaction for that customer.

I built a query which is linked on the customer number, and then I
created a form from that query. Like I said, now when I enter
customer # 3500, it brings in that customer's name, address and
LOCATION. What I want to prevent is, if this is LOCATION XX entry
form, and they key in a customer number who is NOT assigned location
XX, it halts them.

Can I do that? I appreciate your suggestions, and if I were going to
make this a more elaborate project I would probably follow some of
your ideas. However, right now I just want to make it so they can't
enter a transaction for a customer with a different location. I want
to hard-code the locatoin as a validation rule in the entry program.
In other words, if they enter customer 12345 and that is for location
YY and they are working with the location XX form, they won't be able
to do it.

While I'm at it though, can I also have a validate date rule, say the
date they enter has to be greater than 04/15/2008 or a date field in
another file.

Hey, thanks for your help!
ga


Albert D. Kallal said:
An interesting suggestion here is to have your actual database design force
you to follow your user interface design.


does that mean you want to search setup and display a form with a particular
location, and then enter customers into that location?


OK now you talking about bringing up a customer on display, and then entry
transactions for the customer???

you gonna have to decide how you work flow and how your work is going to
court here.

Furthermore what's to stop a person from entering any location out of the
blue? (I notice you ask that question also).

You have to decide how your user interface is going to operate here.

You either

a) search find and display a particular location, and then that location
form will display all the possible customers for that given location

b) search find and display a customer, and then have some type of ability to
select an assigned that customer to a particular given location

c) you want both of the above capabilities.

It seems to that the first thing I would do is build and design a table of
locations. all the information about that location such as where it is in
the city, perhaps who maintains that location, perhaps whatever information
you want about that location, you build a table with all the fields that the
finds that location place. There also might be some kind of location code
also, and include that in the table also.

At this point you're going to have to edit each of the customers now, and
set their location field. It is assumed that this location field will simply
be (store) te ID field that points to the primkary key (id) field of the
table locatons. This also make your application more user friendly, since
for each customer form that you bring up and display, you'll have a nice
combo box that only allows you to assign that customer to one location. Note
while the combo box can (will) store the primary key of id from the
locations table, the combo boxes are designed to display and search by a
descriptive text type field from the locations table (the beauty of this is
thus you can distort the primary key ID in this field from locations, but it
will display the text field, or even perhaps your external location code
that you and your users are used to now.).

at this point than you can build locations form, and the user can search
find that equivocation they want to work on, and the list of customers that
belong to that location who can thus be displayed as a sub form.

when you bring up the customers form, for each customer you can have a sub
form and your table of transactions. there's no need in your table of
transaction to set the location code, because each transaction is related to
customers, and the customers has the location code already set. Dolby no
possibility of a air and shrink the wrong location code into transactions,
because you in fact never actually enter location code into transactions
because you don't have to. the location code and transaction is set by the
mere fact of transactions being attached to a particular customer.

The above a course assumes that one customer can only be in one location,
and if that rules not the case then you'll have to change your designs to
accommodate this issue, but you're not yet alluded to this issue yet.

So, we have

locations-->
customers--->
tranactions

George Applegate
(e-mail address removed)
 
A

Albert D. Kallal

When you load up the form, you simply set (restrict) the combo box to the
customers for that location, and volia....there will be no way to enter a
customer number for that location...

So, simply "set" the combo box record Source to all legal customers

eg:

strSql = "select id, CustomerNum, CustomerName from tblCustomers where
locationID = " & me!LocationID

me.MyComboBox.RowSource = strSql

Now, when you go to select the customer number, you can either type the
customer number into the combo box, or drop down the combo box to
"search/list" the companies (which thus also serves as a means to lookup
company names, and show the customer number to help the user during data
entry).
The transaction form has a "customer #" field on it

Ah, great...make this text box a combo box as per above, and simply make
sure hte combo box has it "set limits to list" = yes...

The only additional issues here that might come up is depending on how you
allow navigation in the main form that might cause the location to change.

You could also just put some code in the before update of the customNum
field that looks up the location for the customer , and then gives user a
message

dim vLocation as varient

vLocation = dlookup("locationID","tblCustomers","CustomerNum = " &
me.CustomerNum)

if isnull(vLocation) then
' custor not found...give message
msgbox "not a legal customer"
cancel = true
exit sub
else
if vLocation <> me.Location then
msgbox "wrong location for custoerm"
cancel = true
end if
end if

In the above, me.Location is the value of the "locationID"...

Note that by setting cancel=true, the before update event will stop and the
cursor will remain focused on that text box (customerNum)

The above assumes the customer number is an actual number type data field in
the table, if it is not then you'll have to modify the above code to
surround the customer number with quotes when you execute the SQL.
 
G

George Applegate

Albert,

Okay...more questions:

I get how to change the form to a combo box. But after that I'm sort
of lost.

I assume I am entering this code in code builder for the box?

Does it go between the "private sub" and "end sub"?

What is me.mycombobox.rowsource = strsql?

In my "code" as written it shows like this:

Private Sub CustomerID_BeforeUpdate(Cancel As Integer)
strSql = "select id, CustomerID, Lastname, Firstname from Customer
where Location = & me!'99'"

Me.mycombobox.RowSource = strSql
End Sub

But it doesn't work. What am I doing wrong???

Location is text so I put quotes around the '99'

When I say I am basic, I mean "basic".

A couple of other questions...if I have another field that I want to
be only "good" or "bad" filled in, how can I make those the only two
values allowed? There may be other values in the table itself, but on
the form I only want them to be able to enter "good" or "bad" in
another field.

Thanks,
ga


Albert D. Kallal said:
When you load up the form, you simply set (restrict) the combo box to the
customers for that location, and volia....there will be no way to enter a
customer number for that location...

So, simply "set" the combo box record Source to all legal customers

eg:

strSql = "select id, CustomerNum, CustomerName from tblCustomers where
locationID = " & me!LocationID

me.MyComboBox.RowSource = strSql

Now, when you go to select the customer number, you can either type the
customer number into the combo box, or drop down the combo box to
"search/list" the companies (which thus also serves as a means to lookup
company names, and show the customer number to help the user during data
entry).


Ah, great...make this text box a combo box as per above, and simply make
sure hte combo box has it "set limits to list" = yes...

The only additional issues here that might come up is depending on how you
allow navigation in the main form that might cause the location to change.

You could also just put some code in the before update of the customNum
field that looks up the location for the customer , and then gives user a
message

dim vLocation as varient

vLocation = dlookup("locationID","tblCustomers","CustomerNum = " &
me.CustomerNum)

if isnull(vLocation) then
' custor not found...give message
msgbox "not a legal customer"
cancel = true
exit sub
else
if vLocation <> me.Location then
msgbox "wrong location for custoerm"
cancel = true
end if
end if

In the above, me.Location is the value of the "locationID"...

Note that by setting cancel=true, the before update event will stop and the
cursor will remain focused on that text box (customerNum)

The above assumes the customer number is an actual number type data field in
the table, if it is not then you'll have to modify the above code to
surround the customer number with quotes when you execute the SQL.

George Applegate
(e-mail address removed)
 
A

Albert D. Kallal

George Applegate said:
Albert,

Okay...more questions:

I get how to change the form to a combo box. But after that I'm sort
of lost.

That is a "strange" term to say change a form to a combo box.

A form is something in which you can "place" a combo box on. So you can
place text boxes on a form, you can place combo boxes on a form, you can
place radio buttons on a form etc. However you would not say that you change
a form to a text box, or you change a form to a combo box. You're new to MS
access and grasping all these terms can be a bit of a challenge here.
Anyway, you can't really change a form into a combo box. I suppose from user
interface point of view, there are cases where you might use a form to
prompt the user for something, or you might decide to use a combo box, but
form and combo box are not really interchangeable terms.
I assume I am entering this code in code builder for the box?

yes, if you're talking about the text box in which you plan to enter the
location code.

My suggestion here is that we want to "load up" the combo box with **only**
customers for that location. The problem we not solved yet is how/when/where
you're going to define what location you're working on (I assume a text box
on the form where you enter the location code). We could use what is called
an unbound text box at the top of the form where we enter in the location
code were going to work on. This is an important detail here because when we
select a location is **when** the code is going to run to restrict a combo
box of customers to this particular location. As mentioned, if you had a
table of locations, then the user could simply select a location from a nice
list generated by a combo box. However since we don't have a predefined
table of locations then we likely just have to use a un-bound text box in
which the user enters the location. So, we are assuming that
our form is going to be built and based on the transactions table.

I would suggest that we simiply get the combo box working on this form. Use
the wizard to build this combo box of customers on this form. Once you get
the combo box working, then we can add code to *restrict* the combo box to
customers just for that location. So, let's do one thing at a time here, and
simply build a combo box that lists the customers.

Does it go between the "private sub" and "end sub"?

Ah, yes if you talking about the after update event for the text box where
you enter the loction code (if you're talking about some other scenario,
then no). So, **when** we set the location is were/when our code will run
that will *restrict* the list of customers to a particular location.
That means we're going to use the after update event of the location text
box.

As mentioned, the first column of the combo box should be the primary key of
customers (id, or whatever name you gave the primary key field). This "id"
value of course is the value we are going to store in the transactions
table. The second column of the combo box can be the customer name, or
whatever way you identify the customer, perhaps customer number?

I also notice with your design right now that since the location code is
attached to the customers, then it means that one customer can only have
transactions from one location. It's also absolutely critical for your
design that we decide if a customer can have transactions from more than one
location, or they *always* going to be assigned to only one location? The
reason why this is important is that if a customer's always to be from one
location, then we put the location field in the customer table (as you have
now). However if a person can purchase and have transactions from different
locations, then we have to put the location field in the transactions table.
So it is kind of interesting that answers to these real world questions will
actually dictate how we design our tables.

The code that runs in the after update event of our un-bound location text
box will look like:

dim strSql as string

strSql = "select id, CustomerNum, CustomerName
from tblCustomers where locationID = " & me.txtLocationTextBoxNameGoesHere

me.MyComboBox.RowSource = strSql

Note that the above SQL string you use above should match the SQL code
generated by the wizard that you used to make the combo box. (you can
actually cut and paste the SQL from the combo box into the code editor in
this case). also that above line of code strSql = "select..." is actually on
one line in the code editor, but text based news readers here, there's
likely word wrapping occuring...
 
G

George Applegate

Mr. Kallal,

Thanks again for a very detailed reply. I am afraid I am getting this
more complicated all the time. You are giving me great information
but I am not explaining it clearly so I'm starting over...again.

Let me start from the beginning with a new example, as this is a very
similar project I am working on, so if I can get one to work, the
other will work..

Let's say I have two tables: Employee and Punches with the fields
shown:

Employee Punches
EmployeeID links to EmployeeID
Name Date
Department Time
City Inout

Now, I created a query from the tables as follows:

Punches Employee ID
Empmloyee Name
Employee Department
Employee City
Punches Date
Punches Time
Punches Inout

Next I used ACCESS to create an entry form from the query. I just
highlighted my query and then went to "create form" and voila, a form
was created.

And I used the wrong terminology. It created a lot of entry boxes on
the form, but they default to text box or whatever??? I figured out
how to change the employee ID box to be a combo box. That's what I
meant.

As you can see, an employee is fixed assigned a Department. Only one
department.

I want to create an entry form for each department in my company. I
don't need to have a department table, althought I could, because the
employee file is populated (downloaded) from another source - so the
employee table is always FIXED data, including the department.

However, I want to create a separate entry for each department so they
can only enter Punches for employees that belong to that deparment.
In other words, so department 35 can only enter punches for employees
who are desigated as department 35.

So, If a department is "35" that entry form can only see employees
from department 35. Right now, on the form, if I enter employee 25,
and press enter, it brings in their name and department and city
automagically. However, I want to create an entry form so the only
employee #'s the person can enter are employees who have been assigned
department 35.

I changed the employee ID textbox on my form to be a combo box
(remember, I let access create the form for me by highlighting the
query and clicking create form).

Okay, I changed the box to be a combo box, and I can see it's going to
let me scroll down, but where I get lost is how to enter the code you
are giving me. I go into design view, and then click build and then
code builder and it defaults to "before update". I changed the
before update to after update.

It puts a private sub and end sub in automatically, and I tried to
emulate the code gave me ending up with this:


Private Sub Department_AfterUpdate()

Dim strSql As String

strSql = "select EmployeeID, Name, City from Employee where
Department = " & Me.txtDepartment

Me.MyComboBox.RowSource = strSql

End Sub

I save that and then open it. I try to scroll down on the combo
employee id box, but no employees appear. I am trying to figure out
how to code this strsql statement. I only want employees with a
department of "35" to show in the scroll down combo box.
Unfortunately, I'm getting no employees now.

Obviously, I have gone awry...I have to be making this way more
complicated than it needs to be. I am guessing I need to make this
strsql something like:
Select employeeid, name, city from employee where deparment = " &
me.35 or something like that??? Or am I totally way, way off base.

I confess I am a novice, but I've worked with data bases on other
computers (IBM AS/400 - don't laugh) so I'm not without some basic
understanding here.

One other question on the form: Field Inout -

Lets say I want to validate Inout to either be "IN", "OUT" or (blank).
I tried to do that through validation data. I made that to be = "IN"
or "OUT" or " ".

But if I try to press enter, leaving it blank, it doesn't like it. IN
works and OUT works, but just pressing enter (leaivng it blank) gives
me my validation message which I put in which says "must be in, out or
blank"

Whew...that's a lot of typing. If you read all that and it makes
sense, I'll be surprised. But I'm hopeful you can glean something out
of my rambling. I also understand maybe I could be doing with split
database or front end/back end, but I'm not interested in going there
right now. I want to get the basics and then graduate to something
else.
George Applegate
(e-mail address removed)
 
C

Clif McIrvin

Hi George. I'm going to guess that Mr. Kallal is trying to take the
weekend off, so I'll jump in here and see if I can help out a bit.


Next I used ACCESS to create an entry form from the query. I just
highlighted my query and then went to "create form" and voila, a form
was created.

And I used the wrong terminology. It created a lot of entry boxes on
the form, but they default to text box or whatever??? I figured out
how to change the employee ID box to be a combo box. That's what I
meant.

Terminology: Access created a "form" that contains "controls." "Text
box" is one type of control that allows you to type text into the
field -- hence the name Text Box. (When you are typing, the digits and
the letters are all text.) A "Combo Box" combines (combination,
shortened to Combo) functionality of a list box (which allows you to
choose from a list, but not to type into it) and a text box. So: the
entry form you are wnating to create is, in fact, an Access form. The
"entry boxes" are Access form controls.
As you can see, an employee is fixed assigned a Department. Only one
department.

I want to create an entry form for each department in my company. I
don't need to have a department table, althought I could, because the
employee file is populated (downloaded) from another source - so the
employee table is always FIXED data, including the department.

As the employee table is fixed I would agree that there seems to be no
need for a department table. However, as I read down your description I
would suggest that you build a Department Query against your Employee
Table.

Ok. With Access, you don't need a different form for each department;
what you need is a method for Access to know which department is loading
the form. (This raises another question: is each department working from
a different computer? We'll come back to this question later.)
However, I want to create a separate entry for each department so they
can only enter Punches for employees that belong to that deparment.
In other words, so department 35 can only enter punches for employees
who are desigated as department 35.

So, If a department is "35" that entry form can only see employees
from department 35. Right now, on the form, if I enter employee 25,
and press enter, it brings in their name and department and city
automagically. However, I want to create an entry form so the only
employee #'s the person can enter are employees who have been assigned
department 35.

This can be accomplished by the SQL restriction that Albert is
describing to you. However, before he, or I can help you do that you
need to let us know more about how Access is supposed to know which
department it is supposed to be working with.

Assuming that the user is going to somehow choose the department, you
can use the unbound control (unbound text box) that Albert describes.
Personally, I would reccomend using a Combo Box that is bound to the
Department Query I mentioned earlier. This way the user can either enter
the department number or choose it from a list.
I changed the employee ID textbox on my form to be a combo box
(remember, I let access create the form for me by highlighting the
query and clicking create form).

Okay, I changed the box to be a combo box, and I can see it's going to
let me scroll down, but where I get lost is how to enter the code you
are giving me. I go into design view, and then click build and then
code builder and it defaults to "before update". I changed the
before update to after update.

It puts a private sub and end sub in automatically, and I tried to
emulate the code gave me ending up with this:
Private Sub Department_AfterUpdate()

Question: You just referred to "employee ID combo box" and this code is
in the "Department" control after update event. I'm going to assume
that this is the Employee Department text box created by Access when you
had it build the form for you. You need to add a new control to your
form, and your code will attach to this new control. I'll assume your
new control will be called "cboChooseDepartment" so the code will change
to:


Private Sub cboChooseDepartment_AfterUpdate()

Dim strSql As String

strSql = "select [Punches Employee ID], [Employee Name], [Employee City]
from [Employee Query Name Here] where [Employee Department] = " &
Me.cboChooseDepartment

Me.[Employee ID].RowSource = strSql

End Sub

Note that everything between "strSql=..." and "Me.[Employee
ID].RowSource = strSql" is all one line, so if you're doing a copy and
paste you will probably need to put it back together after you paste.
There are a total of five (5) lines in this subroutine.

Also, everything I put inside of square brackets are names that come
from the query you built ... you need to replace my suggestions with
your actual names. The square brackets are necessary anytime there is a
space in the name.
I save that and then open it. I try to scroll down on the combo
employee id box, but no employees appear. I am trying to figure out
how to code this strsql statement. I only want employees with a
department of "35" to show in the scroll down combo box.
Unfortunately, I'm getting no employees now.

When you open the form, you need to choose a department from the Choose
Department Combo Box before you try to select an employee. After you
choose a department, you should find a list of employees in your
Employee ID Combo Box.
Obviously, I have gone awry...I have to be making this way more
complicated than it needs to be. I am guessing I need to make this
strsql something like:
Select employeeid, name, city from employee where deparment = " &
me.35 or something like that??? Or am I totally way, way off base.

I'd call this the learning process <grin>. I think I can follow your
thinking here, and I'd say that the "off base" is mostly just not being
familiar with how Access is put together. Keep at it, try to make sense
out of what comes up when you hit F1 (built in help) -- use F1
frequently! -- keep coming back here, and you'll find that it will come
together for you.

I confess I am a novice, but I've worked with data bases on other
computers (IBM AS/400 - don't laugh) so I'm not without some basic
understanding here.

So as you begin to learn Access' ways things will begin to fall into
place because you have something to relate to! said:
One other question on the form: Field Inout -

Lets say I want to validate Inout to either be "IN", "OUT" or (blank).
I tried to do that through validation data. I made that to be = "IN"
or "OUT" or " ".

But if I try to press enter, leaving it blank, it doesn't like it. IN
works and OUT works, but just pressing enter (leaivng it blank) gives
me my validation message which I put in which says "must be in, out or
blank"

Did you try pressing a single space before you hit enter? I'm not sure
if Access will recognize that or not. Access recognizes Null as a valid
value -- that's null, as in "nothing at all", and when you press enter
in an empty field Access wants to leave it Null which violates your
validation rule. Nulls can be usefil, but they can also cause problems
if you don't handle them properly so you likely do want to stay with " "
as the third value.

You might try putting " " as the default value, then just pressing enter
will leave the single space.
Whew...that's a lot of typing.

Yup. But that's how problems get solved said:
If you read all that and it makes
sense, I'll be surprised.

Why? You have that little faith in your level of knowledge? Your ideas
/ questions do make sense.
But I'm hopeful you can glean something out
of my rambling. I also understand maybe I could be doing with split
database or front end/back end, but I'm not interested in going there
right now. I want to get the basics and then graduate to something
else.

Good place to come back to my earlier question about how the different
departments will access the database. If you are going to have multiple
(as in simultaneous) users, then you will be going to a FE/BE (that is
what split databse means) eventually. As long as this is strictly a
development / testing database and you are the only one touching it that
can wait until you're further along the learning curve <g>. In fact,
that's where I am with my first Access application. It's nowhere near
done, but it's time to delve into splitting and multi-user capability.


I suggested that you build an Employee Department Query. I know of two
ways to do that but I don't know what the differences are in terms of
performance impact. Build a Query against your Employee Table that
contains only the Department field (sorted ascending.) In Design View,
Select View | Totals from the menu to add the "Total" property to your
design grid. You want "Group By" (the default on my computer.)

The second method does not use the Totals property. Instead, from the
Design View, Select View | SQL View and change "SELECT" to "SELECT
DISTINCT". As I said, I don't know which to prefer; I mention this
only in case Albert (or someone else) wants to comment on the
differences. The first method might be preferable for a beginner simply
because it uses built-in design tools and does not require editing the
SQL.
 
A

Albert D. Kallal

I changed the employee ID textbox on my form to be a combo box
(remember, I let access create the form for me by highlighting the
query and clicking create form).
Okay, I changed the box to be a combo box, and I can see it's going to
let me scroll down

Sure, that makes sense. Be careful when you on a existing transaction
record because playing with the combo box will be selecting/changing the
customer for that transaction record your form is currently on.

but where I get lost is how to enter the code you
are giving me. I go into design view, and then click build and then
code builder and it defaults to "before update". I changed the
before update to after update.

No, we going to place a UN-BOUND text box on our form called

txtLocation

This un-bound text box should be at the top of our form (good spot in the
forms header).
Private Sub Department_AfterUpdate()

NO NO... we not placing this code behind the actual "bound" department
field on the form. That will NOT work at all.

So, with our design, you going to enter in the department number into this
text box, and we need to accomplish 3 goals:

1) make the form ONLY display transactions + customers from that location

2) load up the customer combo box with ONLY customers from that location

3) when we add a new record, might as well make the location the default
what
we typed in our above un-bound text box. Note in fact that there is NO NEED
to display the location field in the actual form, since we have a text box
at the top of the screen where we enter the location. This also saves during
data entry and also eliminates a whole bunch of "prompt + error" code
messages from the user because we already have the location code set in the
top of the screen. We just setup the location default to this text box
during data entry, and that way users can't enter the wrong location because
they don't have to enter it anymore for each new transaction! We simply use
the location code already entered "once" by the user.

So, the after update event of this txtLocation box, we do the 1st 2 goals:

dim strSql as string

strSql = "select * from qryYouMade where location = '" & me.txtlocation &
"'"

Me.ReocrdSource = strSql

' the above filters/sets our form to ONLY display transactions from that
location.

' we *could* leave the combo box alone, but lets also set it to this
customer list
' also

strSql = "select id,Customer??,?? from tblCustomers where location = '" &
me.textLocation & "'"
me.MyCustomercomboBox.RowSource = strSql

(this sql MUST MATCH THE SQL GENERATED by the wizard for your customer combo
box..so, look at that sql for the comb box, and MAKE SURE it has the same
columns, and in the SAME order.

And, to setup the default location during data entry, we simply use the
forms before insert event, and go:

me!Location = me.txtLocation

That is it. It will take less time to do the above then it takes me to type
this response..

Also, make sure that query is editable before you make the form via the
wizard (this might be a trouble point at this time also).

I would of couse leave the location field visible for the testing phase
here, but you can evetnally remove the "bound" location box from the form,
since we always be able to see the txtLocation box we placed at the top of
the form...
 
G

George Applegate

Clif - and Albert,

Okay, you guys lost me again...not your fault (grin), I'm a
sloooowwwwwwww learner.

You are wondering how I know what department the user wants to enter
punches for. My idea was to create separate queries for each
department, and I thought of perhaps having some security on it that
only authorized users for that department could open the query and
related form for that department. That was my ORIGINAL thought.

Now you threw me a curve and said, put a text box on the form and let
the user enter the department they want to work with. I can buy into
that, but then and there you lost me...well sort of...

So, trying to do that, I created a control on my form for a
txtDeparment for them to enter. I also created a department query,
that, with a little help from you guys, I want to figure out how to
have it be a combo select box where they can pick the department they
want.

How do I do that? I think we are back to the code builder?

Can you help me do this? To add the control for them to enter the
department they want to work with, I opened the form in design view.
Then, do I insert an activeX control, or what kind of a control am I
entering??? I think I should choose Activex Control and then
Microsoft Fomrs 2.0 ComboBox??? Is that correct? I then renamed it
txtDepartment.

Okay, now I have the txtDepartment combo box on the form. I also
created a query of departments. How do I code it so it shows me the
available departments? I assume I have to right click and choose code
builder??

That's my first sticking point. I want the user to be able to select
what department from the scroll down combo box, or alternatively,
enter a department.

Next, I have a combo box also for employeeid. How do I code it to
show employees that only match the txtDepartment that is selected by
the user??? Isn't that where you guys are trying to lead me??

What is the significance of "after update"...vs "before update"?
Also, when in code builder, do I see all the code for all the combo
boxes that are written? In other words, there isn't a separate code
fore each combo box? It's all in one big piece of code and prefaced by
private sub and end sub???? Is that basically correct??

I think you are advising me to have this entry combo box on my form
for the user to enter the department. I get that, and have the combo
box added assuming I did that right and it's a MS Forms 2.0 combobox.
Can you help me with the code builder to show department choices?

The query I built over the Employee file/department is "Department
Query".

Should it look something like:

private sub txtDepartment_AfterUpdate()
dim strSql as String
strSQL = "select * from [Department Query]
??
End Sub

As you can see, I lost myself! :) Am I on the right track there
though, to have the possible departments shown doing something like
that??

Next, assuming I get that far, how do I code the employeeID control
code builder part, so it only shows employees who have a department
assigned to them that matches the txtDepartment?

txtDepartment is an alphameric field; we are using numeric codes, but
it's defined is alphanumeric. Department is also an alphanumeric
field. So do I somehow need to use quotes in part of this (")

Okay, have I gotten off the beaten path again? Albert, some of the
code you wrote has quotes and single quotes and I got lost on that.

I feel we would accomplish a small miracle here if you guys can get me
across the goal line and help me get the combo box to show the
possible departments when I click the arrow on the txtDepartment box
(the one I am letting the user enter), and secondly, if you can then
help me translate that into then only displaying employees for that
department when I click on the arrow down button for the employeeId
field in the form.

I have no doubt that once I get one of these stupid combo boxes to
work (Only stupid because of my stupidity), I will finally figure out
how to "emulate" it on future ones.

Thanks in advance,
ga









Clif McIrvin said:
Hi George. I'm going to guess that Mr. Kallal is trying to take the
weekend off, so I'll jump in here and see if I can help out a bit.


Next I used ACCESS to create an entry form from the query. I just
highlighted my query and then went to "create form" and voila, a form
was created.

And I used the wrong terminology. It created a lot of entry boxes on
the form, but they default to text box or whatever??? I figured out
how to change the employee ID box to be a combo box. That's what I
meant.

Terminology: Access created a "form" that contains "controls." "Text
box" is one type of control that allows you to type text into the
field -- hence the name Text Box. (When you are typing, the digits and
the letters are all text.) A "Combo Box" combines (combination,
shortened to Combo) functionality of a list box (which allows you to
choose from a list, but not to type into it) and a text box. So: the
entry form you are wnating to create is, in fact, an Access form. The
"entry boxes" are Access form controls.
As you can see, an employee is fixed assigned a Department. Only one
department.

I want to create an entry form for each department in my company. I
don't need to have a department table, althought I could, because the
employee file is populated (downloaded) from another source - so the
employee table is always FIXED data, including the department.

As the employee table is fixed I would agree that there seems to be no
need for a department table. However, as I read down your description I
would suggest that you build a Department Query against your Employee
Table.

Ok. With Access, you don't need a different form for each department;
what you need is a method for Access to know which department is loading
the form. (This raises another question: is each department working from
a different computer? We'll come back to this question later.)
However, I want to create a separate entry for each department so they
can only enter Punches for employees that belong to that deparment.
In other words, so department 35 can only enter punches for employees
who are desigated as department 35.

So, If a department is "35" that entry form can only see employees
from department 35. Right now, on the form, if I enter employee 25,
and press enter, it brings in their name and department and city
automagically. However, I want to create an entry form so the only
employee #'s the person can enter are employees who have been assigned
department 35.

This can be accomplished by the SQL restriction that Albert is
describing to you. However, before he, or I can help you do that you
need to let us know more about how Access is supposed to know which
department it is supposed to be working with.

Assuming that the user is going to somehow choose the department, you
can use the unbound control (unbound text box) that Albert describes.
Personally, I would reccomend using a Combo Box that is bound to the
Department Query I mentioned earlier. This way the user can either enter
the department number or choose it from a list.
I changed the employee ID textbox on my form to be a combo box
(remember, I let access create the form for me by highlighting the
query and clicking create form).

Okay, I changed the box to be a combo box, and I can see it's going to
let me scroll down, but where I get lost is how to enter the code you
are giving me. I go into design view, and then click build and then
code builder and it defaults to "before update". I changed the
before update to after update.

It puts a private sub and end sub in automatically, and I tried to
emulate the code gave me ending up with this:
Private Sub Department_AfterUpdate()

Question: You just referred to "employee ID combo box" and this code is
in the "Department" control after update event. I'm going to assume
that this is the Employee Department text box created by Access when you
had it build the form for you. You need to add a new control to your
form, and your code will attach to this new control. I'll assume your
new control will be called "cboChooseDepartment" so the code will change
to:


Private Sub cboChooseDepartment_AfterUpdate()

Dim strSql As String

strSql = "select [Punches Employee ID], [Employee Name], [Employee City]
from [Employee Query Name Here] where [Employee Department] = " &
Me.cboChooseDepartment

Me.[Employee ID].RowSource = strSql

End Sub

Note that everything between "strSql=..." and "Me.[Employee
ID].RowSource = strSql" is all one line, so if you're doing a copy and
paste you will probably need to put it back together after you paste.
There are a total of five (5) lines in this subroutine.

Also, everything I put inside of square brackets are names that come
from the query you built ... you need to replace my suggestions with
your actual names. The square brackets are necessary anytime there is a
space in the name.
I save that and then open it. I try to scroll down on the combo
employee id box, but no employees appear. I am trying to figure out
how to code this strsql statement. I only want employees with a
department of "35" to show in the scroll down combo box.
Unfortunately, I'm getting no employees now.

When you open the form, you need to choose a department from the Choose
Department Combo Box before you try to select an employee. After you
choose a department, you should find a list of employees in your
Employee ID Combo Box.
Obviously, I have gone awry...I have to be making this way more
complicated than it needs to be. I am guessing I need to make this
strsql something like:
Select employeeid, name, city from employee where deparment = " &
me.35 or something like that??? Or am I totally way, way off base.

I'd call this the learning process <grin>. I think I can follow your
thinking here, and I'd say that the "off base" is mostly just not being
familiar with how Access is put together. Keep at it, try to make sense
out of what comes up when you hit F1 (built in help) -- use F1
frequently! -- keep coming back here, and you'll find that it will come
together for you.

I confess I am a novice, but I've worked with data bases on other
computers (IBM AS/400 - don't laugh) so I'm not without some basic
understanding here.

So as you begin to learn Access' ways things will begin to fall into
place because you have something to relate to! said:
One other question on the form: Field Inout -

Lets say I want to validate Inout to either be "IN", "OUT" or (blank).
I tried to do that through validation data. I made that to be = "IN"
or "OUT" or " ".

But if I try to press enter, leaving it blank, it doesn't like it. IN
works and OUT works, but just pressing enter (leaivng it blank) gives
me my validation message which I put in which says "must be in, out or
blank"

Did you try pressing a single space before you hit enter? I'm not sure
if Access will recognize that or not. Access recognizes Null as a valid
value -- that's null, as in "nothing at all", and when you press enter
in an empty field Access wants to leave it Null which violates your
validation rule. Nulls can be usefil, but they can also cause problems
if you don't handle them properly so you likely do want to stay with " "
as the third value.

You might try putting " " as the default value, then just pressing enter
will leave the single space.
Whew...that's a lot of typing.

Yup. But that's how problems get solved said:
If you read all that and it makes
sense, I'll be surprised.

Why? You have that little faith in your level of knowledge? Your ideas
/ questions do make sense.
But I'm hopeful you can glean something out
of my rambling. I also understand maybe I could be doing with split
database or front end/back end, but I'm not interested in going there
right now. I want to get the basics and then graduate to something
else.

Good place to come back to my earlier question about how the different
departments will access the database. If you are going to have multiple
(as in simultaneous) users, then you will be going to a FE/BE (that is
what split databse means) eventually. As long as this is strictly a
development / testing database and you are the only one touching it that
can wait until you're further along the learning curve <g>. In fact,
that's where I am with my first Access application. It's nowhere near
done, but it's time to delve into splitting and multi-user capability.


I suggested that you build an Employee Department Query. I know of two
ways to do that but I don't know what the differences are in terms of
performance impact. Build a Query against your Employee Table that
contains only the Department field (sorted ascending.) In Design View,
Select View | Totals from the menu to add the "Total" property to your
design grid. You want "Group By" (the default on my computer.)

The second method does not use the Totals property. Instead, from the
Design View, Select View | SQL View and change "SELECT" to "SELECT
DISTINCT". As I said, I don't know which to prefer; I mention this
only in case Albert (or someone else) wants to comment on the
differences. The first method might be preferable for a beginner simply
because it uses built-in design tools and does not require editing the
SQL.

George Applegate
(e-mail address removed)
 
G

George Applegate

Albert/Clif,

I am close...

I created a department query that shows a list of all departments.

On my form I added an unbound combo box called "txtDepartment". When
I open my form to enter/update, I can select the scroll arrow on the
txtDepartment combo box and sure enough, my departments show and I can
choose the one I want. :) :)

On the form I have the following fields:
txtDepartment (which the user enters)
RCDID (assigned by access)
EmployeeID (from Employee file)
Department (from Employee file)
Last Name (from Employee file)
First Name (from Employee file)
InOut (from Punches file)
DeleteCode (from Punches file)

Here is what I want to do. If the user enters "35" for the
txtDepartment, how do I code the EmployeeID combo box to show only
employees who are assigned that department? Can I do that?

i created another query called EmployeeQuery which gives me a list of
employees by department. Somehow, this is what I want to do. When
the user enters the department they want in txtDepartment (i.e. 35), I
then want the only employeeID's to show on that scroll box to be
employeeid's of employees who have a department that matches
txtDepartment. I am thinking I use that EmployeeQuery I created?

If I right click on the text box and choose code-builder, this is what
I end up with (which doesn't work)::
-------------------------------------------------------------------------------------------------------

Private Sub EmployeeID_BeforeUpdate(Cancel As Integer)

Dim strSql As String

strSql = "select EmployeeID from [EmployeeQuery] where Department = "
& Me.txtDepartment

Me.EmployeeID.RowSource = strSql

End Sub
---------------------------------------------------------------------------------------------------

I am wondering if I don't have the right Private sub information, i.e.
should it be the following??? Is the BeforeUpdate the problem, or is
the sub name wrong??? Or do I have to have some additional quotes
because it's alphameric?

Private Sub txtDepartment_AfterUpdate(Cancel as Integer)

I feel I am very close now, just am not sure how to make this link
yet. Does it have anything to do with the fact that the department is
alphanumeric, not just numeric???

Any help you'd be kind enough to give would be GREATLY APPRECIATED.

Thanks,
ga

George Applegate
(e-mail address removed)
 
G

George Applegate

Albert/Clif:

I am now MUCH, MUCH closer, just need to ask a couple more ?'s.

If I enter 99 in for txtDepartment I get a "data type mismatch in
criteria expression. If however, I put in "99" (with quotes), then it
works...well sort of. I still have a couple of issues:

Here is what my code looks like:
-------------------------------------------------------------------------------------------------------------------

Private Sub txtDepartment_AfterUpdate()

Dim strSql As String

strSql = "select EmployeeID, LastName, Firstname from [EmployeeQuery]
where Department = " & Me.txtDepartment

Me.EmployeeID.RowSource = strSql

End Sub
----------------------------------------------------------------------------------------------------------------

I'm guessing I need to put something like a ' or a " before and after
&me.txtDepartment??? Maybe I can figure that out.

The other thing is, when I do the scroll down box of EmployeeID, it
only shows employeeID, it doesn't show Lastname or firstname. If I
change it to be select * from [EmployeeQuery] then I just get
department. I figured "*" would mean show me all fields but maybe
that just means the first field in the query??

How can I get it to show employeeID, lastname and firstname all 3 in
the selection list??? My EmployeeQuery has Department, EmployeeID,
LastName and FirstName in it. Or won't it do this?

TIA, ga


George Applegate
(e-mail address removed)
 
A

Albert D. Kallal

George Applegate said:
Albert/Clif:

I am now MUCH, MUCH closer, just need to ask a couple more ?'s.

Great stuff!
If I enter 99 in for txtDepartment I get a "data type mismatch in
criteria expression. If however, I put in "99" (with quotes), then it
works...well sort of. I still have a couple of issues:

Excellent follow-up and troubleshooting notes.
Private Sub txtDepartment_AfterUpdate()

Dim strSql As String

strSql = "select EmployeeID, LastName, Firstname from [EmployeeQuery]
where Department = " & Me.txtDepartment

change above to:
strSql = "select EmployeeID, LastName, Firstname from [EmployeeQuery]
where Department = '" & Me.txtDepartment & "'"

We using single quotes above because they are easier to put in the code....

The other thing is, when I do the scroll down box of EmployeeID, it
only shows employeeID, it doesn't show Lastname or firstname.

You have to specify the number of columns in the combo box, and you sql MUST
match that number of columns. I had suggested that you build the combo box
with the wizard, as it will let you select (and more important size) the 3
columns. You can even just temp build a combo box on the form, steal some of
the settings, and cut/paste those settings from that combo box the wizard
just made into your existing combo box. If you don't want to use the wizard,
then open up the properties sheet for the combo box while in design mode
for that form, and enter 3 for the "list width". columns, and set the size
for each column in the combo box 1;1;1 in the column widths. In fact if
users never see or search by the actual employee ID, then you can set the
first column to zero, and you can actually search by last name (or first
name, whichever the second column will be. (in your case the above SQL has
the last name as the second column, so that's what we'll be able to search
by).
If I
change it to be select * from [EmployeeQuery] then I just get
department. I figured "*" would mean show me all fields but maybe
that just means the first field in the query??

The SQL is actually returning all of the collums, but a combo box needs to
told how many collums, and the "display" width for each collum. This is
another good reason why we generally build combo boxes with the wizard. You
have the combo box made already, so try and tweak it. If you can't get the
collums to display, then give the wizard a try...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top