Re: Coding with varsortby and options
- From: John Nurick <j.mapSoN.nurick@xxxxxxxxxxxxxx>
- Date: Tue, 07 Feb 2006 22:01:11 +0000
Not unless you tell me what it does that you think it shouldn't, or what
it doesn't do that you think it should, and what line of code the
problem occurs at.
On Tue, 7 Feb 2006 12:02:27 -0800, Kat <Kat@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
John,
I can't seam to find the issue. Can you please review the code to make sure
I am not missing something:
Private Sub WRACmd_Click()
'Dim stDocName As String
Dim varhowsort As Variant
Dim varsortby As Variant
Dim vardate As Variant
Dim vardateto As Variant
Dim varFM As Variant
Dim varID As Variant
Dim varNH As Variant
Dim varTrade As Variant
varsortby = Me!FrameSortBy
vardate = Me!CboDateFrom
vardateto = Me!CboDateTo
varFM = Me!CboFM
varID = Me!CboID
varNH = Me!CboNH
varTrade = Me!CboTrade
'This is if all empty
If (vardate = "") And (vardateto = "") And (varFM = "") And (varID = "") And
(varNH = "") And (varTrade = "") Then
Select Case varsortby
Case 1: stDocName = "WRAbyDate"
Case 2: stDocName = "WRAbyFM"
Case 3: stDocName = "WRAbyID"
Case 4: stDocName = "WRAbyNH"
Case 5: stDocName = "WRAbyTrade"
End Select
'This is if date empty
ElseIf (varFM = "") And (varID = "") And (varNH = "") And (varTrade = "") Then
Select Case varsortby
Case 1: stDocName = "WRAbyDate1"
Case 2: stDocName = "WRAbyDate2"
Case 3: stDocName = "WRAbyDate3"
Case 4: stDocName = "WRAbyDate4"
Case 5: stDocName = "WRAbyDate5"
End Select
'This is if FM Empty
ElseIf (vardate = "") And (vardateto = "") And (varID = "") And (varNH = "")
And (varTrade = "") Then
Select Case varsortby
Case 1: stDocName = "WRAbyFM1"
Case 2: stDocName = "WRAbyFM2"
Case 3: stDocName = "WRAbyFM3"
Case 4: stDocName = "WRAbyFM4"
Case 5: stDocName = "WRAbyFM5"
End Select
'This is if ID Empty
ElseIf (vardate = "") And (vardateto = "") And (varFM = "") And (varNH = "")
And (varTrade = "") Then
Select Case varsortby
Case 1: stDocName = "WRAbyID1"
Case 2: stDocName = "WRAbyID2"
Case 3: stDocName = "WRAbyID3"
Case 4: stDocName = "WRAbyID4"
Case 5: stDocName = "WRAbyID5"
End Select
'This is if NH Empty
ElseIf (vardate = "") And (vardateto = "") And (varFM = "") And (varID = "")
And (varTrade = "") Then
Select Case varsortby
Case 1: stDocName = "WRAbyNH1"
Case 2: stDocName = "WRAbyNH2"
Case 3: stDocName = "WRAbyNH3"
Case 4: stDocName = "WRAbyNH4"
Case 5: stDocName = "WRAbyNH5"
End Select
'This is if Trade Empty
ElseIf (vardate = "") And (vardateto = "") And (varFM = "") And (varID = "")
And (varNH = "") Then
Select Case varsortby
Case 1: stDocName = "WRAbyTrade1"
Case 2: stDocName = "WRAbyTrade2"
Case 3: stDocName = "WRAbyTrade3"
Case 4: stDocName = "WRAbyTrade4"
Case 5: stDocName = "WRAbyTrade5"
End Select
End If
If Len(stDocName) > 0 Then
DoCmd.OpenReport stDocName, acViewPreview
Else
MsgBox "No Report Selected."
End If
DoCmd.OpenReport stDocName, acViewPreview
End Sub
"John Nurick" wrote:
This probably means that you're calling DoCmd.OpenReport without passing
its report name argument, or that the variable you think contains a
report name is in fact empty.
Set a breakpoint (see Help for details on breakpoints and debugging) at
the beginning of your code and step through it to see just what's
happening.
On Tue, 17 Jan 2006 12:46:03 -0800, Kat <Kat@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
Thank you.
I must be the most hard headed person. Now I get an error of:
The action or method requires a Report Name argument.
Error 2497
"John Nurick" wrote:
This probably means that you made a mistake entering the code. If the
error appeared at the ElseIf line, it's likely that you omitted the
preceding End Select or included an End If.
On Thu, 12 Jan 2006 12:37:02 -0800, Kat <Kat@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
I get an error message when I input the code and made the changes. By the
way the suggestion on control names was great thanks.
The error message I get is:
Else without If
"John Nurick" wrote:
1) Always declare
Option Explicit
at the beginning of each module. This forces you to declare all your
variables and thus protects you from many code errors, especially those
caused by typing mistakes.
2) It is a good idea to use descriptive names for controls. E.g. instead
of Frame108, call it something like fraSortBy. Instead of Combo6,
cboDateFrom.
3) Your code would be much easier to read - and therefore easier for you
to debug and improve - if you restructure it to make the conditional
tests and flow of control cleare. For instance, most of the present code
could be replaced by something like this. Note how the If statements are
laid out so it is easy to see the differences between them:
If (varDate = "") And (varDateTo = "") _
And (varFM = "") And (varNH = "") And (varTrade = "") Then
Select Case varSortBy
Case 1: stDocName = "WRAbyDate"
Case 2: stDocName = "WRAbyFM"
Case 3: stDocName = "WRAbyID"
Case 4: stDocName = "WRAbyNH"
Case 5: stDocName = "WRAbyTrade"
End Select
ElseIf (varID = "")_
And (varFM = "") And (varNH = "") And (varTrade = "") Then
Select Case varSortBy
Case 1: stDocName = "WRAbyDate1"
Case 2: stDocName = "WRAbyDate2"
Case 3: stDocName = "WRAbyDate3"
Case 4: stDocName = "WRAbyDate4"
Case 5: stDocName = "WRAbyDate5"
End Select
End If
'Open the report
DoCmd.OpenReport stDocName, acViewPreview
On Wed, 11 Jan 2006 10:52:02 -0800, Kat <Kat@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
I know the string that I am using works but I have restrutured it. What I
am trying to do is have a varsortby option and combo box drive mulitply
reports. All the quiers and reports have been tested they work. However,
when I use process button where I created the string of code to combine the
use of a option button (varsortby) and the combo box (selected item) it skips
the combo box selections. I am not sure if the varysortby field type of one
of them would effect it. But one field type I have is a autonumber. Would
that create the error?
Here is the string:
Private Sub Command25_Click()
syscursor = 5
Dim stDocName As String
Dim varhowsort As Variant
Dim vardate As Variant
Dim vardateto As Variant
Dim varFM As Variant
Dim varID As Variant
Dim varNH As Variant
Dim varTrade As Variant
varsortby = Me!Frame108
vardate = Me!Combo1
vardateto = Me!Combo6
varFM = Me!Combo2
varID = Me!Combo3
varNH = Me!Combo4
varTrade = Me!Combo5
'These reports handel all of sort by are selected and not combo box
stDocName1 = "WRAbyDate"
stDocName2 = "WRAbyFM"
stDocName3 = "WRAbyID"
stDocName4 = "WRAbyNH"
stDocName5 = "WRAbyTrade"
'These reports handel all the sort by for the date field for each combobox
stDocName6 = "WRAbyDate1"
stDocName7 = "WRAbyDate2"
stDocName8 = "WRAbyDate3"
stDocName9 = "WRAbyDate4"
stDocName10 = "WRAbyDate5"
'These reports handel all the sort by for the FM for each combobox
stDocName11 = "WRAbyFM1"
stDocName12 = "WRAbyFM2"
stDocName13 = "WRAbyFM3"
stDocName14 = "WRAbyFM4"
stDocName15 = "WRAbyFM5"
If varsortby = 1 And vardate = "" And vardateto = "" And varFM = "" And
varID = "" And varNH = "" And varTrade = "" Then GoTo Adate
If varsortby = 2 And vardate = "" And vardateto = "" And varFM = "" And
varID = "" And varNH = "" And varTrade = "" Then GoTo BFM
If varsortby = 3 And vardate = "" And vardateto = "" And varFM = "" And
varID = "" And varNH = "" And varTrade = "" Then GoTo CID
If varsortby = 4 And vardate = "" And vardateto = "" And varFM = "" And
varID = "" And varNH = "" And varTrade = "" Then GoTo DNH
If varsortby = 5 And vardate = "" And vardateto = "" And varFM = "" And
varID = "" And varNH = "" And varTrade = "" Then GoTo ETrade
'This will show the WRA report seleted by date and sorted(handles each sortby)
If varsortby = 1 And varFM = "" And varID = "" And varNH = "" And varTrade =
"" Then
DoCmd.OpenReport stDocName6, acViewPreview
GoTo SkipOver
End If
If varsortby = 2 And varFM = "" And varID = "" And varNH = "" And varTrade =
"" Then
DoCmd.OpenReport stDocName7, acViewPreview
GoTo SkipOver
End If
If varsortby = 3 And varFM = "" And varID = "" And varTrade = "" Then
DoCmd.OpenReport stDocName8, acViewPreview
GoTo SkipOver
End If
If varsortby = 4 And varFM = "" And varID = "" And varTrade = "" Then
DoCmd.OpenReport stDocName9, acViewPreview
GoTo SkipOver
End If
If varsortby = 5 And varFM = "" And varID = "" And varTrade = "" Then
DoCmd.OpenReport stDocName10, acViewPreview
GoTo SkipOver
End If
Adate: DoCmd.OpenReport stDocName1, acViewPreview
GoTo SkipOver
BFM: DoCmd.OpenReport stDocName2, acViewPreview
GoTo SkipOver
CID: DoCmd.OpenReport stDocName3, acViewPreview
GoTo SkipOver
DNH: DoCmd.OpenReport stDocName4, acViewPreview
GoTo SkipOver
ETrade: DoCmd.OpenReport stDocName5, acViewPreview
GoTo SkipOver
SkipOver: End
Exit_Command25_Click:
Exit Sub
--
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.
--
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.
--
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.
--
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.
.
- Follow-Ups:
- Re: Coding with varsortby and options
- From: Kat
- Re: Coding with varsortby and options
- References:
- Re: Coding with varsortby and options
- From: Kat
- Re: Coding with varsortby and options
- Prev by Date: Re: Unexplained code is running!
- Next by Date: Re: link a subform instead of separate form ..... stLinkCriteria
- Previous by thread: Re: Coding with varsortby and options
- Next by thread: Re: Coding with varsortby and options
- Index(es):
Relevant Pages
|