Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filling in a date field based on a previous selection

Status
Not open for further replies.

RnRExpress

Technical User
Oct 24, 2004
53
US
Here is what I have been trying to do.

I have a "reason" field, whioch you can select a reason for issuing a loaned piece of equipment. There are six, such as Claim, Lost, Waiting for Parts, borrowing, DOA, and Agent. Then there is a date field, which you enter the date the loaned equipment was given tot he customer. Now I have a 2nd date field, called "Duedate". I would like for that field to be filled in automatically, based on the "Reason" field and "Date Issued" field.

In other words, if the Reason was "Claim" and the date Issued was 12/1/05, then I want the DueDate to be 15 days after the issued date, or 2/15. If the reason was "agent", and it was issued on 2/1 then the Duedate would be the issued date + 60. Each reason would be a certain number of days past the issued date.

I have tried using If/And statements but that seems clumsy and I havent had that great of luck, but then again, its probably the way I am putting it in.

Any suggestions would be greatly appreciated.

Richard
 
its probably the way I am putting it in
Why not posting the code you tried explaining what didn't work ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Ok, here is what I tried. Ovbiously I am a novice at this kind of stuff.

If Reason = "Agent Repair" then Me.DueDate = DateLoaner + 45
else
If reason = "Waiting For Inv." then Me.DueDate = DateLoaned + 30
else
Me.DueDate = DateLoaner + 15
End If
 
I can see some typing errors here
Code:
If Reason = "Agent Repair" then Me.DueDate = DateLoane[COLOR=red]r[/color] + 45
else
If reason = "Waiting For Inv." then Me.DueDate = DateLoane[COLOR=green]d[/color] + 30
else
Me.DueDate = DateLoane[COLOR=red]r [/color]+ 15


Zameer Abdulla
Jack of Visual Basic Programming, Master in Dining & Sleeping
Visit Me
 
[tt]select case reason
case "Agent Repair"
Me.DueDate = DateLoaned + 45
case "Waiting For Inv."
Me.DueDate = DateLoaned + 30
case else
Me.DueDate = DateLoaned + 15
end select[/tt]

But for the future, what happens if there are more "reasons" to determine different intervals? Do you wish to alter the code everytime?

I think I'd consider the following

Table as rowsource of the reason combo:

[tt]tblReason
id - pk
Reson - text
Interval - numeric (byte?)[/tt]

Base the combo on the table, include all three fields, let key column be hidden, as suggested by the wizard, also have the third column invisible (column width for instance; 0;1.4;0)

In a relevant event, after both the issue date and combo contains a value, try something like this:

[tt]me!txtDueDate=me!txtIssueDate + val(me!cboReason.colum(2))[/tt]

Perhaps a test here, either for me.newrecord, to only apply it on new records, or test whether there's any content in the due date control, so you don't overwrite if you don't intend to.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top