TempVar only loads when I step thru

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

TempVar only loads when I step thru

Post by Jeff H »

I can't see what's wrong with this code in Access. When I step through the code, txtWeek on the report is populated with the TempVar dWk. When I run it normally, it is not.

The cmdTier1 button is on the Dashboard:

Code: Select all

Private Sub cmdTier1_Click()
Dim Wk As Double
Wk = CDbl(InputBox("Current week"))
TempVars.Add "iSort", 2
TempVars.Add "sSort", "Tier, Plant"
TempVars.Add "sSortLabel", "By Plant Name"
TempVars.Add "dWk", Wk
DoCmd.Close
DoCmd.OpenReport "rptIndexTier1", acViewPreview
DoCmd.Maximize
DoCmd.RunCommand acCmdZoom100
End Sub
When rptIndexTier1 opens this runs:

Code: Select all

Private Sub Report_Load()
If Not IsNull(TempVars!sSort) And Not IsNull(TempVars!iSort) Then
    Me.optsSort = TempVars!iSort
    Me.OrderBy = TempVars!sSort
    Me.lblSort.Caption = TempVars!sSortLabel
    Me.txtWeek = TempVars!dWk
    TempVars.Remove "iSort"
    TempVars.Remove "sSort"
    TempVars.Remove "sSortLabel"
    TempVars.Remove "dWk"
Else
    Me.optsSort = 1
    Me.OrderBy = "Index"
    Me.lblSort.Caption = "By Index Number"
End If
End Sub

User avatar
HansV
Administrator
Posts: 78468
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: TempVar only loads when I step thru

Post by HansV »

Could you create a copy of the database, strip away everything that isn't relevant to the problem, as well as all sensitive information, then zip the copy and attach the zip file to a reply?
Best wishes,
Hans

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

Re: TempVar only loads when I step thru

Post by Jeff H »

Will do. It'll have to be sometime tomorrow.

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

Re: TempVar only loads when I step thru

Post by Jeff H »

Well, I tried to strip it down some and ended up messing things up so I had to restore my backup.
Looking for a simplified example of just this issue, I made a couple of changes and it seems to be working now. I removed the TempVar bit and put the Inputbox in the report Load event. At that point I had the same problem (stepping through populated the textbox, running the procedure did not). So I rem'd out everything except

Code: Select all

Me.txtWeek.Value = InputBox("Enter the week")
and it worked, un-rem the other code and it didn't. Then I put the Inputbox at the end of the code. Now it works.

Do you have any idea why putting that line at the bottom made a difference? Whether you do or not, thanks for making me look deeper. Problem solved.

- Jeff

User avatar
HansV
Administrator
Posts: 78468
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: TempVar only loads when I step thru

Post by HansV »

Did you still have the line

Code: Select all

If Not IsNull(TempVars!sSort) And Not IsNull(TempVars!iSort) Then
Best wishes,
Hans

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

Re: TempVar only loads when I step thru

Post by Jeff H »

Yes. All of the other TempVar stuff is still the same. The only difference is instead of a TempVar for the value of txtWeek, I used an Inputbox directly and made it the last line in the procedure.

User avatar
HansV
Administrator
Posts: 78468
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: TempVar only loads when I step thru

Post by HansV »

Presumably, the condition Not IsNull(TempVars!sSort) And Not IsNull(TempVars!iSort) was not satisfied, so if-true part was not executed.
Best wishes,
Hans

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

Re: TempVar only loads when I step thru

Post by Jeff H »

I don't think that was it because all those TempVars worked fine throughout. In fact, I'd set my breakpoint on that If-line and the true part did execute.

User avatar
HansV
Administrator
Posts: 78468
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: TempVar only loads when I step thru

Post by HansV »

It works now, so it's probably not worth pursuing this further, but if you wish, you can still attach the database.
Best wishes,
Hans

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

Re: TempVar only loads when I step thru

Post by Jeff H »

Thanks for the offer, but I agree, this instance works now so I'll wait and see if get something similar in the future.