Form Header problem

  • Thread starter Thread starter Haim Beyhan
  • Start date Start date
H

Haim Beyhan

Hi,

I'm using Access 2002. I have a continuous bound form.
I have also a textbox on form header, which I enter date and the form shows
the records according to this date. Now, this works without problem. I have
also 2 buttons under the textbox in form header which should show me the day
before and the other one the day next.
The problem is, when I click one of the 2 commands to show me the day before
or the next day, the textbox is not updated although msgbox shows the
correct value.

txtFITRH is the textbox on the form header which should show the correct
date value when I click the buttons.

Private Sub cmdPrevDay_Click()
tmpdate = DateAdd("d", -1, tmpdate)
ShowDay
End Sub

Private Sub cmdNextDay_Click()
tmpdate = DateAdd("d", -1, tmpdate)
ShowDay
End Sub

Private Sub ShowDay()
txtFITRH = tmpdate
Me.InputParameters = "@ptrh1 datetime='" & tmpdate & "', @ptrh2
datetime='" & tmpdate & "', @pfno1 nchar(7)=NULL, @pfno2 nchar(7)=NULL,
@pftip tinyint=Forms!FrmImalat!fraTip"
End Sub
 
Hi Haim,

Not sure but could be a typo:

tmpdate = DateAdd("d", -1, tmpdate) in cmdNextDay_click should be:

Private Sub cmdNextDay_Click()
tmpdate = DateAdd("d", 1, tmpdate)
ShowDay
End Sub

Add 1 one instead of minus one day.

I made a little modification and tested the code, it would fine on my side,
the textbox is updated successfully.

Could you follow the steps and let me know if it works?

1. Open NothWidow.adp, or create a new adp connecting to NorthWind database
in Sql server.

2. Create a new form via Form Wizard, bound it to Orders table.
3. In form header, as you mentioned, add one text box and two command
button.
4. Build code, copy and paste the following code:

Option Compare Database
Option Explicit
Dim tmpdate As Date

Private Sub cmdNextDay_Click()

tmpdate = DateAdd("d", 1, tmpdate)
ShowDay
End Sub

Private Sub cmdPrevDay_Click()

tmpdate = DateAdd("d", -1, tmpdate)
ShowDay

End Sub

Private Function ShowDay()

txtFITRH = tmpdate

'Chr(39)

Me.InputParameters = "OrderDate datetime=Forms!Orders!txtFITRH"


End Function

Private Sub Form_Load()

tmpdate = #7/4/1996#
txtFITRH = tmpdate

End Sub

5. Save the changes and run the form, click the button, the date is updated
successfully.

Please feel free to reply to the threads if you have any concerns or
questions.




Sincerely,

Alick Ye, MCSD
Product Support Services
Microsoft Corporation
Get Secure! - <www.microsoft.com/security>

This posting is provided "AS IS" with no warranties, and confers no rights.




--------------------
| From: "Haim Beyhan" <[email protected]>
| Subject: Form Header problem
| Hi,
|
| I'm using Access 2002. I have a continuous bound form.
| I have also a textbox on form header, which I enter date and the form
shows
| the records according to this date. Now, this works without problem. I
have
| also 2 buttons under the textbox in form header which should show me the
day
| before and the other one the day next.
| The problem is, when I click one of the 2 commands to show me the day
before
| or the next day, the textbox is not updated although msgbox shows the
| correct value.
|
| txtFITRH is the textbox on the form header which should show the correct
| date value when I click the buttons.
|
| Private Sub cmdPrevDay_Click()
| tmpdate = DateAdd("d", -1, tmpdate)
| ShowDay
| End Sub
|
| Private Sub cmdNextDay_Click()
| tmpdate = DateAdd("d", -1, tmpdate)
| ShowDay
| End Sub
|
| Private Sub ShowDay()
| txtFITRH = tmpdate
| Me.InputParameters = "@ptrh1 datetime='" & tmpdate & "', @ptrh2
| datetime='" & tmpdate & "', @pfno1 nchar(7)=NULL, @pfno2 nchar(7)=NULL,
| @pftip tinyint=Forms!FrmImalat!fraTip"
| End Sub
|
|
|
 
Your code requires and assumes that tmpdate has been defined as a
variable at the top of your code module, before either of those three
procedures, to make it global to those procedures.

Otherwise, if you don't do that, and you have not said Option Explicit
at the start of your module, the three tmpdate variables are actually
three *different variables*, each one local to the procedure in which
you've referenced it.

In any case, it is not good practice to pass information via globals,
unless you have to. You should change your code to pass the calculated
date value to the ShowDay procedure as a parameter. That procedure
then receives the value as a parameter. Then you do not need the
module-global tmpdate variable.

HTH,
TC
 
Back
Top