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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CommandButton to Populate Month in textbox 1

Status
Not open for further replies.

Mandyxoxo

Programmer
Jul 15, 2008
11
US
I am trying to build a form for the user to pick date constraints. The form has two text boxes, one called txtStartDate1 and txtEndDate1. Below the two text boxes there are four command buttons. The first command button is labeled today and if pressed populates today's date in the text boxes. The second is labeled week and if pressed populates the text boxes with dates for this week (ex for this week: txtStartDate1: 7/14/2008 and txtEndDate1: 7/18/2008). The third command button is to populate the month. For example in the first text box it would populate 7/1/2008 and then find the end date for the current month. Lastly, I want to have a button with year. Both month and year do not work. I have the following code listed below and then the error that is being generated.

For Month:
txtStartDate1 = DateSerial(Year(Date), Month(Date), 1)
txtEndDate1 = DateSerial(Year(Date), Month(Date) + 1, 0)

Error: Object doesn't support this property or method.

I tested the code in VBA with a messagebox and everything works great. The problem is when I put the textbox = to the code.

For Year I have:

txtStartDate1 = CDate("01/01/" & Year(Date))
txtEndDate1 = DateAdd("d", -1, DateAdd("yyyy", 1, Me!txtStartDate1))

I still get the same error of: Object doesn't support this property or method. What am I doing wrong or what am I missing?

Any help is greatly appreciated!

 
The information in the text boxes are taken and are run through a query that generates the report with the dates specified. However, the text boxes themselves are unbound.

In the textboxes, the commandbutton can be used to populate the text box or the user can input their own dates. The purpose of the month and year are so the user can press those commandbuttons and have the dates automatically show up in the textboxes without having to enter anything manually.

Setting the value to txtStartDate1.Value does not work.

It just keeps saying Object does not support this property or method.
 
Your syntax works. I even placed the Me! before the controlnames and still works. I tried both bound and unbound. Works. So either you have a typo, or maybe a missing library. Check a database that's working's references (in VBA, Tools-References).
You could try recreating the form (no copying) or export it to another database and try it.
Like I said, when I try to duplicate the error I can't. It just works.
 
I have created two different forms and neither work. What reference should I specifically try adding? That is probably it...
 
I have Access 2000. This is the list, and order, I usually have:
Visual Basic For Applications
Microsoft Access 9.0 Object Library
OLE Automation
Microsoft DAO 3.6 Object Library
Microsoft ActiveX Data Objects 2.5 Library
Microsoft ActiveX Data Objects Recordset 2.5 Library
Microsoft Windows Common Controls 6.0

Make sure you have the latest version numbers.

If you search the Access forums, you'll find code to check your references.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top