Problem adding to time

ombadboy

Registered User.
Local time
Today, 12:29
Joined
Feb 9, 2007
Messages
30
Am trying to add (2) to the date found in the field Date Loaned, but it isnt quite working


Private Sub DueDate_BeforeUpdate(Cancel As Integer)
Test = "[Date Loaned]"

Set [DueDate] = DateAdd("d", 2, Test)

End Sub

Ive tried different alternatvies such as [Loans]![Date Loaned], ive tried alot of different work arounds, but didnt manage to make it work..

Any ideas?
 
In your form, use the TEXTBOX names, but essentially it would be:
Code:
Me.DueDate = DateAdd("d", 2, Me.DateLoaned)
 
In your form, use the TEXTBOX names, but essentially it would be:
Code:
Me.DueDate = DateAdd("d", 2, Me.DateLoaned)


doesnt quite work.. i get a "#Name?"
 
I don't think you can alter any information in a controls before update event. I think you can only cancel the input from the user.

Try stuffing the code in the after update event of the control which is the source of the information ([Date Loaned]?). (if the control is unbound, you might need it in the on current event of the form too)

And as boblarson says, you should use the names of the text controls when referencing. If they contain spaces, use [brackets].
 
I don't think you can alter any information in a controls before update event. I think you can only cancel the input from the user.

Try stuffing the code in the after update event of the control which is the source of the information ([Date Loaned]?). (if the control is unbound, you might need it in the on current event of the form too)

And as boblarson says, you should use the names of the text controls when referencing. If they contain spaces, use [brackets].

The source of information comes from [Date Loaned] from the "Loans" table which has is used as a subform in the main form am working with ("Members")
 
I don't think you can alter any information in a controls before update event. I think you can only cancel the input from the user.
Actually Roy you can alter information in the BeforeUpdate event. That's where you can, for example, change a text box to the current date/time, put user name, for audit trails, etc. and I do it all the time.

If getting #Name, then the liklihood is that the control and the field are the same name. Try renaming the control to txtDateLoaned and txtDueDate and then reference that in the formula.
 
boblarson,

as you can see from the quote, I discuss the before update event of the control, as is the case with the original code, where you can't change the value of the control in it's own before update event. Says both I and the help file.

"A run-time error will occur if you attempt to modify the data contained in the control that fired the BeforeUpdate event in the event's procedure." (any typos are mine)
 
tried using = DateAdd("d", 2, Me.DateLoaned) in the text box..

also changed it to txtDateLoaned

but i still get the "#Name?" error..
 
If the due date is alwas 2 days after the loan date then don't store it, just calculate it on the fly
in the text box control source
=DateAdd("d", 2, [DateLoaned])

no need for the me. in controls only in code.

HTH

Peter
 
If the due date is alwas 2 days after the loan date then don't store it, just calculate it on the fly
in the text box control source
=DateAdd("d", 2, [DateLoaned])

no need for the me. in controls only in code.

HTH

Peter

w00t.. sweet worked now..

i thought i tried that.. but seems i didnt ;) or i forgot the [] probably..

thnx
 

Users who are viewing this thread

Back
Top Bottom