Control Date Value From Command Click

  • Thread starter Thread starter sixteen
  • Start date Start date
S

sixteen

Guest
Dont be overwhelmed by the following, but it may require some extensive thought and I dont expect everyone to understand....

I want to have a unbound form control a subform. On the form I have an unbound text area entitled txtDate. In this area it displays the current date being viewed. I have put left and right buttons on the main form that will add (+1) one day to the date being shown and subtract (-1) one day from the date being shown. I want to conrol it though the "On Click" but I dont know what to enter in the "On Click" field that will allow me this. The reason is, co-insiding with the previous, when the date is changed, the subform is also changed to a new day. Therefore instead of displaying 24 hours of today, you can view 24 hours of yesterday, tomorrow and so on. See, if one is to set the onclick to be: Me.txtDate=Me.txtDate-1, or Me.txtDate=Me.txtDate+1, it calls for a custom macro and I dont know why. I know it somehow resides in some similar command set up.

I also need to know how to make the subform bound but continous, and what exactly does that mean?

Anyone care to offer some assistance? :confused:
 
probably not the best way but...

on form load I'd set txtDate to the current date (check out the date function in access's help).

for the on click I'd set the txtDate to the current date +/- 1 depending on which button they click (again using the date function).

the way I'd load the subform using a query based on the date shown you can use [forms]![formname]![txtDate] in your query to pass the value.

then on each button click you just requery the sub form.

for your continuous form...not real sure about that one, almost sounds like you'd want it in datasheet view. you can do that in the properties of the subform.
 
Welcome to the wonderful world of Access VBA!

You are attempting to set the On Click property to a Visual Basic statement, which doesn't work. You need to use the Code Builder. Click on the [...] button next to the property and select Code Builder. This should bring up the Visual Basic Editor with a screen something like this:
Code:
Private Sub CommandDecrease_Click()

End Sub
(The above example assumes that it is dealing with a Command Button named CommandDecrease_Click)

Between the first and last line in the above example, enter the line:
Me.txtDate=Me.txtDate-1

The onscreen result should then look something like:
Code:
Private Sub CommandDecrease_Click()

Me.txtDate=Me.txtDate-1

End Sub

You will notice, when you go back to the properties box, in the On Click property it should say: [Event Procedure]. This indicates that the On Click property has been set to reference a Sub inside of the form's Visual Basic Code Module.
 
yeah I used the code builder, and I got it to change the main forms date, but as for changing the subform and displaying only entries from the date chosen in the main form, thats now working too well
 
Nevermind I figured it out. As stated before I used an unbound text area, entitled 'txtDate'. Then I Added my subform (bound and continuous) but did not use the wizard. By setting the Parent Source of the suubform to txtDate on the subform and the name of the date on my subforms table as the child source, I was able to get them to control each other. Access automatically hid what wasn't using the same date, and thus it was complete. I will post a link to the end result of what I created later tonite
 

Users who are viewing this thread

Back
Top Bottom