Database design question

MarinaJ

Registered User.
Local time
Yesterday, 21:29
Joined
Jun 26, 2002
Messages
19
I'm starting a database from scratch and this is what I intend to accomplish.

Give choice of Herbicides registered for a specific forage crop to control weeds selected.

With Alex's help, I have created cascading combo and list box for the user to select the type of crop and then crop.

Now the fun part! I have counted 56 weeds and 36 herbicides.

How do I present this on my form to make it easy for the user to select and pick from the list.

The user needs to first select his crop, then weed(s).

To give you a better picture of the scope of the database, I also need to include the following:

1. Select Crop (done)
2.
 
second part

(for some reason it did not accept my full post)

1. Select Crop (done)
2. Select weed

RESULTS
3. Give a list of herbicides registered to use on your crop, and on the weed(s) you selected.

In addition to this I also have many notes to include:

The more complex ones refer to both crop and herbicide results

Basically notes for weeds and herbicides; notes for crops and herbicides.

Any help in design would be appreciated, I hope I'm explaining it clearly enough.

Overwhelmed but determined . . .
Marina
 
I would need to know more specifics about your table structure to walk you through actually setting it up. But I could tell you how I would go about designing the form itself

Towards the top of the form would be the two combo boxes to select the crops and weeds. To the right of this I would have a memo field that displayed notes concerning the crop which was selected from the combo box.

Towards the bottom of the form would be a subform with the 3rd combo box that will contain all the registered herbicides for the selected crop/weed. In the Row Source of the combo box, you would need to set the criteria back to the form so it filtered out non applicable herbicides. Also in this section would be the second memo field that displayed notes on the herbicide which was selected.
 
How do I best display my weeds, If I use a multiple list box, the user will have to scroll up and down to verify his selection of weeds. I would like to keep them all in sight. Can I split up my list (56 weeds) into various boxes or will this complicate it too much.
or
can I make columns in my list box which will act independantly of each other?

Also, I cannot include the memo field for the crop at this point because it is dependant on the result (herbicide choice).

I think I understand the third part, it will be similar to the cascading boxes rowsource setup. I didn't realize you could insert a combo box in a subform, I like that idea I'll look into it.

One part I don't understand is, if I'm referring to my combos for the crop and weed, they where do the herbicides fit in? The crop selection will always change, so I thought I had to create a table which will indicate the following:

HerbID (lookups)
Herb

WeedID (lookups)
weed

CropID
Crop
HerbID
WeedID

Then what/how do I link this to my combo box? My guess is a query which I will ask for "Herb", but what do I know.

Thanks,
Marina
 
Okay, I was making what you want to do simpler than it actually is. I didn't consider that multiple weeds could be selected for the same crop. The best solution I've ever seen for something of this nature was two list boxes. When the user first goes in, one would have all the weeds and the other would be empty. The user could then drag items from the list of weeds into the empty list box which would be the weeds they are actually dealing with.

As for the rest of your questions, I don't think I'm fully understanding what you are wanting. Are the detailed notes only referring to the particular combination of crop and herbicide? If so, then you would only need one memo field in your subform (based on the herbicide chosen from the combo box). Also, how are you currently identifying which herbicide can be use with which weeds and crops? This will affect how you go about getting the source for you herb combo box. From what I am envisioning you would setup a query that filters out all herbicides that cannot be used with the crop you have chosen and the weeds you have chosen (dealing with multiple weeds is unfortunately going to make this difficult). Then the query would group the results by the herbicide name. This way when the user looks at the combo box all they see is a list of herbs which apply to the selections they have chosen above. If the memo field associated with the herb/crop combination is also included in this query, then you will have no problem getting that on your subform as well.
 
Marina,

Here are a few thoughts. You have 3 primary entities; Crops, Weeds, and Herbicides. You have correctly made a table for each. Now you need some tables to "link" the entities.

First you want a CropToWeed table that contains the primary key of the Crop and Weed tables. Every entry in this table expresses that fact that a specific Crop is vulnerable to a specific Weed. You would expect to have multiple entries for each Crop key.

Second you want a WeedToHerbicide table with (surprise) the primary keys of the Weed and Herbicide tables. Each entry is this table expresses the fact that a specific Weed is controlled with a specific Herbicide.

You just might want a third table with CropWeedHerbicide triple. That would be useful if a specific herbicide has warnings when treating a specific weed AND treating for a specific crop.

These tables might only contain keys. Or you might add some texxt or memo fields that describe cautions for a specific CropWeed combination or WeedHerbicide conbination.

The link tables will help you connect combo or list boxes on your forms.

HTH,
RichM
 
Forage Database

I finally have the time to reply to both posts.

doulostheou:

I would appreciate knowing more about dragging items to the second list box. I think that would be ideal.

You asked if the detailed notes only refer to the particular combination of crop and herbicide, the answer is yes. I also have detailed notes which as refer to the particular combination of weed and herbicide. So I would need at least 2 memo boxes (probably three because I found that some weed note had two per weed/herbicide)

You asked how I'm currently identifying which herbicide can be used with which weed.

I basically have a junction table for Weed and Herbicide:

HerbicideID (links to lookup table for herbID and Herb)
Weed ID (links to lookup table for weedID and weeds)
NoteLetterID (points to my noteslookup)
LetterID (points to the same noteslookup table, as some had two notes to them)

I also have a junction table similar to this for Crop and Herbicide:

CropANDTypeID (this allow for a unique number for each crop)
HerbicideID (points to the same lookup table above)
NoteID (to my lookup for crop notes)

Basically, when I enter data in these junction tables, I am only selecting numbers/letters. I have set them up as lookup wizards so I can pick from the list. My information comes from a 4-page foldout, so I have numbered all my information to reflect my database ID numbers. My foldout is set up very similar to a multiplication table.

Crop on top with followed by weeds (in the straight line)
herbs (down the side)

I have made a test query to see if all my data will show up. If I start with my Crops and Herbicides I have no problems bringing in the info. As soon as I add my two weeds tables I get no results from my run. I'm not sure why, I will set all to RI.
(Thanks!)

RichM's:

I have completed the tables you suggested. But I just realized that I did not make the third one (HerbID, WeedID, CropID) would this be why my query does not work when I add my weed?

Currently my two junction tables have HerbID in common.

If I can get my query to extract the information I want I should be ok, right?
What is my next step, set all my tables to RI, I currently do not have them set this way?

I will also be trying to create that third table.

Thanks to both of you, I have made so much progress already!

Marina
 
sorry just need a responce hope you dont mind.....

Where is the Maximise function?

I have a startup form and want it to fill the screen when it opens. I know that all I need to do is set it to maximise but I cant see that in properties!??
 
you wrote
<<
I have completed the tables you suggested. But I just realized that I did not make the third one (HerbID, WeedID, CropID) would this be why my query does not work when I add my weed?
>>

I don't think so. If you want a drill down from Crop to Weed to Herbicide, then 2 "link" tables should be enough; that's CropWeed and WeedHerbicide.

RichM
 
I have checked my tables to enforce RI on all lookup and junction tables and somehow it still will not run any results on my query once I have added my weed tables.

Does my query have to work before I proceed?

I have the 2 junction tables set up, do I enforce RI on those links as well?
 
Well, your query would need all 5 tables; three primary entities and two link tables.

Join:
Crop.CropID to CropWeed.CropID
CropWeed.WeedID to Weed.WeedID
Weed.WeedID to WeedHerbicide.WeedID
WeedHerbicide.HerbicideID to Herbicide.HerbicideID

You will need to fill in some rows in the 2 link tables.

Then the whole mess should appear in your query.

RichM
 
Still not working

I have thought about the Crop to Weeds table and I do not think this table can exist.

Crops and Weeds' common ground are herbicides. I have no data for these two alone.

I have tried your suggestion, and my query will still not show results if I add my weeds table and it's 2 lookups.

My primary tables are:
1. Herbicide (HerbID,Herb,WeedGroup,Notes,Hazards)
2. Weeds (WeedID, Weed)
3. Cropname (CropANDtypeID, croptypeID, crop)
(this is 1 of 2 tables used in a cascading combo box on my form, CropANDtypeID field has been added to have a unique number for each type/crop)

My Junction tables are:
1. JoinHerbCrop
(CropANDtypeID, HerbID, NoteID)

RI set - cropANDtypeID to cropname
RI set - HerbID to Herbicide
RI set - NoteID to a lookup

2. WeedtoHerbicide
(HerbicideID, WeedID, NoteLetterID, LetterID)

RI set - HerbicideID to herbicide
RI set - WeedID to weeds
RI set - NoteLetterID to Lookup for notes
RI set - LetterID (this one points the the same lookup as NoteletterID

I can't see my mistake. I can attach the file (106 kb) if I'm not making any sense.

Lastly, being VERY new to ANY forum, please let me know if my questions should be directed towards the query forum, if I should post a new string, or if what I'm doing is acceptable.

I am so appreciative of all the help I have received so far. Thank you very much.

Marina
 
You wrote
<<
My primary tables are:
1. Herbicide (HerbID,Herb,WeedGroup,Notes,Hazards)
2. Weeds (WeedID, Weed)
3. Cropname (CropANDtypeID, croptypeID, crop)
(this is 1 of 2 tables used in a cascading combo box on my form, CropANDtypeID field has been added to have a unique number for each type/crop)

My Junction tables are:
1. JoinHerbCrop
(CropANDtypeID, HerbID, NoteID)
>>

I don't understand JoinHerbCrop. I think the whold structure should be like this from "top" to "bottom":
1) Crop
2) CropToWeed
3) Weed
4) WeedToHerbicide
5) Herbicide

Crop to Herbicide does not fit in the structure.

If you make a test query that joins all 5 tables, then you can view the output and see if it makes sense.

RichM
 
RichMorrison is more than likely better qualified to address your table/query structure, so I will exit that end of the conversation. Throwing in my two cents would likely just result in more confusion. As for dragging between two lists, I will attempt to detail what is involved.

In your table of weeds, you would add a yes/no field "Selected". Name your list that contains all available weeds "list1" and make its source all weeds whose Selected field was false. Next create a list2 which contains all the weeds which are present in the crop and make its source all weeds whose Selected field is true. You will probably want to sort both lists ascending by weed name.

Next comes the coding (this is not original with me, though I don't know who it came from). I have highlighted two words in red which will need to be changed to the name of your Weeds table and your WeedsID (I wasn't sure if that is what you had called it), respectively. Place the following in your form module:

Code:
Option Compare Database
Option Explicit

Dim DragFrm As Form
Dim DragCtrl As Control
Dim DropTime

Const MAX_DROP_TIME = 0.1

Dim CurrentMode As Integer
Const NO_MODE = 0
Const DROP_MODE = 1
Const DRAG_MODE = 2

Sub DragStart(SourceFrm As Form)
   ' NOTE: You should not use Screen.ActiveForm in place of
   ' SourceFrm because you may be dragging from a subform.
   Set DragFrm = SourceFrm
   Set DragCtrl = Screen.ActiveControl
   CurrentMode = DRAG_MODE
End Sub

Sub DragStop()
   CurrentMode = DROP_MODE
   DropTime = Timer
End Sub

Sub DropDetect(DropFrm As Form, DropCtrl As Control, _
                Button As Integer, Shift As Integer, _
                X As Single, Y As Single)
   ' If a drop hasn't happened, then exit.
   If CurrentMode <> DROP_MODE Then Exit Sub
   CurrentMode = NO_MODE

   ' The timer interval is permitted between the MouseUp event and
   ' the MouseMove event. This ensures that the MouseMove event does
   ' not invoke the Drop procedure unless it is the MouseMove event
   ' that Microsoft Access automatically fires for the Drop control
   ' following the MouseUp event of a drag control. Subsequent
   ' MouseMove events will fail the timer test and be ignored.

   If Timer - DropTime > MAX_DROP_TIME Then Exit Sub

   ' Did we drag/drop onto ourselves?
   If (DragCtrl.Name <> DropCtrl.Name) Or _
      (DragFrm.hwnd <> DropFrm.hwnd) Then
      ' If not, then a successful drag/drop occurred.
  DragDrop DragFrm, DragCtrl, DropFrm, DropCtrl, Button, Shift, X, Y
  End If
End Sub


Sub DragDrop(DragFrm As Form, DragCtrl As Control, DropFrm As Form, DropCtrl As Control, _
              Button As Integer, Shift As Integer, X As Single, Y As Single)
   ' Which form was dropped on?
   ' It is a good idea to use the DragDrop procedure to
   ' determine which drag-and-drop operation occurred; then call
   ' appropriate code to handle the special cases.
   Select Case DropFrm.Name
      Case "frmDragDropListBoxes"
         ListBoxExample DragFrm, DragCtrl, DropFrm, DropCtrl, _
                        Button, Shift, X, Y
      Case Else
         ' For all other cases, copy contents of Drag to Drop
         ' control.
         On Error Resume Next
         DropCtrl = DragCtrl
         If err Then MsgBox Error$
   End Select
End Sub

Sub ListBoxExample(DragFrm As Form, DragCtrl As Control, DropFrm As Form, DropCtrl As Control, _
                    Button As Integer, Shift As Integer, X As Single, Y As Single)
   Dim DB As Database
   Dim SQL As String

   Set DB = CurrentDb()

   ' Create SQL statement to update Selected field of
   ' .. drag/dropped list box item.
   SQL = "UPDATE [COLOR=red]tblWeeds[/COLOR]  SET Selected="

   ' Drag from List1 toggle Selected=True, List2 toggles False.
   SQL = IIf(DragCtrl.Name = "List1", SQL & "True", SQL & "False")
   ' If CTRL key not used, alter dragged value only.
   If (Shift And CTRL_MASK) = 0 Then
         SQL = SQL & " WHERE [[COLOR=red]WeedID[/COLOR]]='" & DragCtrl & "'"
   End If

   ' Run update query to toggle Selected field of Weed record(s).
   DB.Execute SQL

   ' Requery the list box controls to show update lists.
   DragCtrl.Requery
   DropCtrl.Requery

End Sub
 
This is so GREAT!

I will copy this and try it. Thank you very much. Do I straight copy it into the module tab? I'm very new coding. I realize that I have to change my table/field names.

One thing, you mention :
"In your table of weeds, you would add a yes/no field "Selected".
Name your list that contains all available weeds "list1" and make its source all weeds whose Selected field was false."

I can add a yes/no field to my existing weeds table. I'm not sure what you mean by "make it's source all weeds whose selected field was false"

"Next create a list2 which contains all the weeds which are present in the crop and make its source all weeds whose Selected field is true. You will probably want to sort both lists ascending by weed name."

I'm confused here, am I making 2 lists boxes, allowing the user to move which weeds are present in his field to the 2nd list box?
Then am I using the contents of the selected weeds in that 2nd list box to generate a query. If it is, great! How does the yes/no field for weeds come into play? Will the yes/no change depending which listbox the weed is in?

Just to recap, I cannot predetermine a specific weed to a crop, just as I cannot create a crop-weed table. I am including a full list of possible weeds and the user will be the one to select the various few he would like to eliminate from his field.

My form now stands at:
Cascading combo boxes (one for type of crop and one for crop) (this is working)
I have starting creating the two list boxes and I will insert your code.
Then I need a query? to select my highlighted choice of crop/type, my list of weeds which are in the 2nd list box and somehow come up with a list (subform or another listbox) of possible herbicide choices and all the notes associated with it.

Wew! What a challenge for my first database! I must be nuts.

I appreciate your help immensly.
Marina
 
To add the code, go into the design view of your form and click view/code. Just copy and paste it there at the form level. Depending on which version of Access you are using the first two lines may already be there.

As for the list boxes. Let me try to rephrase it a little clearer. This "Selected" field that you add to your table is simply there to indicate which weeds have been selected and which are not. Basically, the source of the list box is a query that will determine which weeds have been selected and which have not. If you have already set up your two list boxes, name one "list1" and the other "list2". Now, go to the properties of list1. Under the data tab, is a property called row source. If you click on that field, 3 dots should appear to the right of it. Click on those 3 dots and you can then define the query which will be the source of the list box. You will want to select 3 fields, your WeedID, your WeedName, and your Selected field (which you just added). I would sort the WeedName ascending. Then you need to add a criteria to the selected field. Type "False" in the criteria field (and uncheck show). If your list box is not already hiding the key (the weedID), you will need to do this next. Go to the Format tab and change the column count to 2. Now set the column widths to 0. List1 should be ready. Repeat the same steps for List2 except this time the criteria for the "Selected" field should be true.

How this comes into play for your final product is that all weeds whose selected field is True are the weeds your user has selected. So you are exactly right. The yes/no field changes depending on which listbox the weed is placed in. Weeds whose selected field is false/0/no (however you like to thinkn about it) are not selected. Weeds whose selected field is true/-1/yes have been selected and hence will be used to obtain the correct herbicide. One thing you will notice is that this will leave the previously selected weeds selected next time you come to the list boxes. If you do not wish this to happen, you would need to write a separate function that changes all of your Selected fields back to False. You will be left with what I believe you desire. You select your crop (I'm assuming from the combo box). You then drag the weeds from the list of all weeds to the list which shows the weeds your actual user is dealing with.

As for your query which will return your herbicide results/notes in the subform, I am going to leave you with RichMorrison. I do not know that I would be able to figure that one out without actually looking at your database (I think better hands on).
 
Marina,

OK, I have reviewed the exchange here about the table structure. Let's leave the implementation to doublethou who is handling it just fine.

From your first post, I assumed that the 3 entities had a "top down" relationship; first Crop, second Weed, third Herbicide. In other words, you would first select a Crop and then see a list of Weeds that infest the selected Crop. Second, you select a Weed and then see a list of appropriate Herbicides. That is the typical method for using "cascading combo/list" boxes.

Later posts suggest that there is no real-world connection of Crop to Weed; any Crop can be infested by any Weed.

Is that correct ?

If so (any Crop to any Weed) then you don't need a CropToWeed junction table.

It sounds like you do need a WeedToHerbicide junction and a HerbicideToCrop junction.

Since the 3 entities don't form a vertical hierarchy, you have to make an arbitrary decision; which entity is "on top", which is second, which is third. Or you can visualize the relationship like a triangle. One entity is the top, the other 2 are both second level.

Does all this make sense ? Let me know.

RichM
 
RichM,

What you are saying makes perfect sense. Sorry if I was not very clear in the beginning.

You are correct in saying that any weed can infest any crop. As such, a crop-weed table cannot exist.

I have created the two junction tables I need. As for which entity is on top, I would tend to put the herbicide because it is the common ground between both crop and weed.

I'm still working on getting the cascading combo's working, (I accidently deleted something) after which I will get my two weeds list box working. Once this is done I'll be posting for the third part.

Thanks for all the advice and help so far.

Marina
 

Users who are viewing this thread

Back
Top Bottom