Might be just a typo in the posting, but you declared
strRecordSource
at the top of your procedure, and then passed:
stRecordSource
Using Option Explicit will help prevent this problem.
Alternatively, is it possible the report might already be open when you
OpenReport? If so, the new OpenArgs is ignored, i.e. it retains the value of
OpenArgs from when it was originally opened.
If neither of those solve the problem, try adding:
Debug.Print stRecordSource just above the OpenReport line
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
<shumaker@cs.fsu.edu> wrote in message
news:1117657476.471599.282660@g43g2000cwa.googlegr oups.com...[color=blue]
>I think the problem lies in my understanding(or misunderstanding) of
> the scope of references.
>
> 'Code from button click event on first form:
> Private Sub Ok_Click()
>
> Dim strRecordSource As String
>
> Dim stDocName As String
> Dim stLinkCriteria As String
>
> 'If we want form view with sums, Else we need the no sums query for
> SummaryReport(because the report calculates the sums) or Form without
> sums
> If Me![IncludeSums].Value And Not Me![ViewDatasheet].Value Then
> strRecordSource = "Exec CountsCombinedDescr '" & Me![BeginDate]
> & "','" & Me![SiteChoice] & "'"
> Else
> strRecordSource = "Exec CountsCombinedDescrNoSum '" &
> Me![BeginDate] & "','" & Me![SiteChoice] & "'"
> End If
>
> 'If datasheet form, then form version of calls, else Report version
> If Me![ViewDatasheet].Value Then
> stDocName = "SummaryDatasheet"
> DoCmd.OpenForm stDocName, acFormDS
> Forms(stDocName).RecordSource = strRecordSource
> Forms(stDocName).Caption = Me![SiteChoice].Column(1)
> Else
> stDocName = "SummaryReport"
> 'pass record source string to the openargs param
> DoCmd.OpenReport stDocName, acViewPreview, , , , stRecordSource
> Reports(stDocName).Caption = Me![SiteChoice].Column(1)
> End If
>
> DoCmd.Close acForm, Me.Name, acSaveNo
>
> Exit_Ok_Click:
> Exit Sub
>
> Err_Ok_Click:
> MsgBox Err.Description
> Resume Exit_Ok_Click
> End Sub
>
> 'Code from the on open event of the Report being opened:
> Me.RecordSource = Me.OpenArgs
>
>
> If instead of using strRecordSource I use a literal:
> DoCmd.OpenReport stDocName, acViewPreview, , , ,"Exec
> CountsCombinedDescrNoSum '" & Me![BeginDate] & "','" & Me![SiteChoice]
> & "'"
>
> Then it works fine. But if I use the original with stRecordSource,
> then somehow OpenArgs is null in the onopen event of the report. I'm
> guessing the object is destroyed by going out of scope, but I thought
> VB used references, so that as long as a reference existed to the
> object then it wouldn't be destroyed?
> My understanding of VB doesn't have a great deal of depth.[/color]