Changing Text Box Control Source with VB?

  • Thread starter Thread starter Chris C.
  • Start date Start date
C

Chris C.

Hi everyone,

On my form, I have a text box called [mindate] which is a date field.
I have another text box called [six]. I also have a command button
called [Command48]. I want the user to be able to click this command
button and Access adds 6 months to [mindate] and puts the value in
[six]. In the OnClick event of the command button I tried this VB, but
it didn't work.

Me.six.ControlSource = "=DateAdd('m',6,[mindate])"

This looks like it should work but it doesn't. Any suggestions?

Thanks,
Chris C.
 
Well....Still doesn't work...but I thought of something that might be
causing the problem. The text box [mindate] is already a calculated
field. Can I physically have a calculated field that is based off a
calculated field?

Thanks,
Chris
 
When I try this VB won't let me not put quotes around the DateAdd
function, so I tried this. It is exactly what you suggested but with
another = sign and quotes:

Me.six = "=DateAdd('m',6,Me.[mindate])"

Now when I try it this string shows up in the text box:

=DateAdd('m',6,Me.[mindate])

But it does not evaluate it. Seems kinda strange.

-Chris
 
Why do you want quotes around the DateAdd function?

I see one other problem with your code. The 'm' should have double quotes
not single.

Me.six = DateAdd("m",6,[mindate])

Another question. Why even do this with a button. Why not just put:

=DateAdd("m",6,[mindate])

in the ControlSource of the textbox?

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
Well it was the double quotes that fixed the problem. Also, I guess I
don't really need to attach this command to the button. I had the
button already there and just was going to stick this command on to the
already existing code, but the more I think about it, I will stick it
in the text box control source directly. Thanks for your assistance!

-Chris
 
Back
Top