Thanks to both of you. I do understand the code and can expand it in each
case to include all the options. I still have a problem though because I do
not know how to make the procedure work. Where do I insert the function --
per the form properties or the field or what? When I was using the "switch"
statement I was inserting in the control source for the field to be filled
with the result. Control source used the "switch" expression but does not
accept code. I know this is lame and stupid but I am not a programmer. I am
very grateful for your attention and help. And, I did not mean to offend --
I apologize. That was my frustration. Now I need to know how to call the
procedure at the right place.
--
nhb -- nc
:
Good luck, Nancy. I'm sure either approach will get you where you need to
go. I would interested to know which way you go with this.
:
Thanks to both Rick and Klatuu. I will try both options and get back to you.
--
nhb -- nc
:
Nancy,
I don't know where you got any negative attitude. I only asked what a
Switch statement is and later said I didn't think much of it. Still don't.
In any case, I have looked at a lot of possibilties. In a perfect world, it
would be best to have a table with the fees structure in it so you don't have
to change your code every time you have a different event. If you consider
that negative, then live with it. Anyway, after about 4 hours of playing
with options, here is what I think will work for you. Since there are more
options than "Both Days", you will have to add some to the code, but I think
you can figure it out.
Function FindFee(strStat As String, strDeadline As String, strDays As
String) As Currency
'Compliments of Dave Hargis
Dim rstFees As ADODB.Recordset
If strStat = "Complimentary" Then
FindFee = 0
Exit Function
End If
'Create a recordset for the options
Set rstFees = New ADODB.Recordset
rstFees.Fields.Append "Stat", adVarChar, 10
rstFees.Fields.Append "Deadline", adVarChar, 2
rstFees.Fields.Append "Days", adVarChar, 20
rstFees.Fields.Append "Fee", adCurrency
'Open the recordset
rstFees.Open
'Load the values in the recordset
'Add Additional lines here for additional options
'Use the first line of the add new as is - it is the field names
'The second line is the values for each field
rstFees.AddNew Array("Stat", "Deadline", "Days", "Fee"), _
Array("Member", "EB", "Both Days", 50)
rstFees.AddNew Array("Stat", "Deadline", "Days", "Fee"), _
Array("Non Member", "EB", "Both Days", 95)
rstFees.AddNew Array("Stat", "Deadline", "Days", "Fee"), _
Array("Student", "EB", "Both Days", 45)
rstFees.AddNew Array("Stat", "Deadline", "Days", "Fee"), _
Array("Member", "PR", "Both Days", 75)
rstFees.AddNew Array("Stat", "Deadline", "Days", "Fee"), _
Array("Non Member", "PR", "Both Days", 120)
rstFees.AddNew Array("Stat", "Deadline", "Days", "Fee"), _
Array("Student", "PR", "Both Days", 60)
rstFees.AddNew Array("Stat", "Deadline", "Days", "Fee"), _
Array("Member", "OS", "Both Days", 95)
rstFees.AddNew Array("Stat", "Deadline", "Days", "Fee"), _
Array("Non Member", "OS", "Both Days", 140)
rstFees.AddNew Array("Stat", "Deadline", "Days", "Fee"), _
Array("Student", "OS", "Both Days", 75)
rstFees.UpdateBatch
'Setting this filter will limit the recordset to 1 row with the correct fee
rstFees.Filter = "[stat] = '" & strStat & "' And [deadline] = '" _
& strDeadline & "' And [days] = '" & strDays & "'"
'Check for EOF to avoid an error in case we passed a bad value to the function
If rstFees.EOF Then
FindFee = -1 ' Return a value that says we could not find it
Else
rstFees.MoveFirst
FindFee = rstFees![fee]
End If
rstFees.Close
Set rstFees = Nothing
End Function
:
Sounds like I'm not getting any help -- just negative reactions. It does
work and I found it exploring a database someone else designed using Access
2000. It's helpful because it permits users to identify the variables and
then produces the correct registration fee.
I will provide more information and hope for a better answer.
My database is for conference registrations. Registration fees vary on
several factors -- membership status, time of registration (early bird, pre
registration, on site), registration selections (1 day, 2 days, special
sessions), etc. An example of an expression using the "switch" function is:
=Switch([RegStat]="Member" And [RegDeadline]="EB" And [RegDays]="Both
Days",50,[RegStat]="Non Member" And [RegDeadline]="EB" And [RegDays]="Both
Days",95,[RegStat]="Student" And [RegDeadline]="EB" And [RegDays]="Both
Days",45,[RegStat]="Member" And [RegDeadline]="PR" And [RegDays]="Both
Days",75,[RegStat]="Non Member" And [RegDeadline]="PR" And [RegDays]="Both
Days",120,[RegStat]="Student" And [RegDeadline]="PR" And [RegDays]="Both
Days",60,[RegStat]="Member" And [RegDeadline]="OS" And [RegDays]="Both
Days",95,[RegStat]="Non Member" And [RegDeadline]="OS" And [RegDays]="Both
Days",140,[RegStat]="Student" And [RegDeadline]="OS" And [RegDays]="Both
Days",75,[RegStat]="Complimentary",0)
Notice that the expression covers only a "both days" option. I cannot
include the other options because of the limit of 12 variations.
My sense is that this would be more efficiently done in code -- I just don't
know how to do that.
I'm hoping for better help and would be very grateful.
--
nhb -- nc
:
Klatuu wrote:
Nancy,
Never heard of a switch statement. Is this something newer than A2K?
I
have not worked in anything new. If you can illucidate, I would
appreciate
It's in the Access 97 Help file.