Solved INSERT INTO NOT WORKIG (1 Viewer)

Sepp1945

Member
Local time
Tomorrow, 04:20
Joined
Feb 12, 2023
Messages
33
Thank you very much, it works perfectly.

May i ask you one more question, please?

i want to set the paid_until day automatically, only weekly & monthly changes, all other entries are for a full year.
I used in the lost focus event of date_paid the following code,
**************************************************
=IIf([Product_ID]="4",DateAdd("ww",1,[Paid_Until]),IIf([Product_ID]="5",DateAdd("m",1,[Paid_Until]),DateAdd("yyyy",1,[Paid_Until])))
************************************************************************
it does not work (4 is weekly, 5 is Monthly)
Thank you very much

Sepp
 

June7

AWF VIP
Local time
Today, 12:20
Joined
Mar 9, 2014
Messages
5,475
Product_ID is a number type so don't put parameter in quote marks. Need to specify field to save value into. Consider:

Me!ProductValue = DateAdd(Switch([Product_ID = 4,"ww", [Product_ID=5,"m", True,"yyyy"), 1, [Paid_Until])
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:20
Joined
Feb 19, 2002
Messages
43,297
I used in the lost focus event of date_paid the following code,
1. The Lost Focus event is not a rational event for this code since you don't want the code to run UNLESS some value was changed. The AfterUpdate of a relevant control is better but best will be the FORM's BeforeUpdate event.
2. Having to hard code the Product_ID in an If statment is very constraining and as you add products ends up requiring a code change for each new product. Add a code in the Product table that identifies whether the update will be by week related or by month.
3. Product_ID is probably numeric so you can't enclose the numbers in quotes.
4. The statement is missing a target field -
=IIf([Product_ID]="4",DateAdd("ww",1,[Paid_Until]),IIf([Product_ID]="5",DateAdd("m",1,[Paid_Until]),DateAdd("yyyy",1,[Paid_Until])))
It should be:
Me.Somefield =IIf([Product_ID]="4",DateAdd("ww",1,[Paid_Until]),IIf([Product_ID]="5",DateAdd("m",1,[Paid_Until]),DateAdd("yyyy",1,[Paid_Until])))
 

Users who are viewing this thread

Top Bottom