Here are my two code for the Report that will be opened.
This Report is in Access and is name rpt1, It isn't opening like it should. Please Help... Thank you. - Private Sub cmdApplyFilter_Click()
-
Dim varItem As Variant
-
Dim strAction_Types_Choices As String
-
Dim strReason_Choices As String
-
Dim strPosition As String
-
Dim strFilter As String
-
Dim StrSortOder As String
-
-
If SysCmd(acSysCmdGetObjectState, acReport, "rpt1") <> acObjStateOpen Then
-
MsgBox "You must open the report first."
-
Exit Sub
-
End If
-
-
For Each varItem In Me.LstAction_Type.ItemsSelected
-
strAction_Types_Choices = strAction_Types_Choices & ",'" & Me.LstAction_Type.ItemData(varItem) & "'"
-
Next varItem
-
If Len(strAction_Types_Choices) = 0 Then
-
strAction_Types_Choices = "Like '*'"
-
Else
-
strAction_Types_Choices = Right(strAction_Types_Choices, Len(strAction_Types_Choices) - 1)
-
strAction_Types_Choices = "IN(" & strAction_Types_Choices & ")"
-
End If
-
-
For Each varItem In Me.LstReason.ItemsSelected
-
strReason_Choices = strReason_Choices & ",'" & Me.LstReason.ItemData(varItem) & "'"
-
Next varItem
-
If Len(strReason_Choices) = 0 Then
-
strReason_Choices = "Like '*'"
-
Else
-
strReason_Choices = Right(strReason_Choices, Len(strReason_Choices) - 1)
-
strReason_Choices = "IN(" & strReason_Choices & ")"
-
End If
-
-
For Each varItem In Me.LstPosition.ItemsSelected
-
strPosition = strPosition & ",'" & Me.LstPosition.ItemData(varItem) & "'"
-
Next varItem
-
If Len(strPosition) = 0 Then
-
strPosition = "Like '*'"
-
Else
-
strPosition = Right(strPosition, Len(strPosition) - 1)
-
strPosition = "IN(" & strPosition & ")"
-
End If
-
-
strFilter = "[Action_Types_Choices] " & strAction_Type_Choices & " AND [Reason_Choices] " & strReason_Choices & " AND [Position]" & strPosition
-
-
If Me.cboSortOrder1.Value <> "Not Sorted" Then
-
strSortOrder = "[" & Me.cboSortOrder1.Value & "]"
-
If Me.cmdSortDirection1.Caption = "Descending" Then
-
strSortOrder = strSortOrder & " DESC"
-
End If
-
If Me.cboSortOrder2.Value <> "Not Sorted" Then
-
strSortOrder = strSortOrder & ",[" & Me.cboSortOrder2.Value & "]"
-
If Me.cmdSortDirection2.Caption = "Descending" Then
-
strSortOrder = strSortOrder & " DESC"
-
End If
-
If Me.cboSortOrder3.Value <> "Not Sorted" Then
-
strSortOrder = strSortOrder & ",[" & Me.cboSortOrder3.Value & "]"
-
If Me.cmdSortDirection3.Caption = "Descending" Then
-
strSortOrder = strSortOrder & " DESC"
-
End If
-
End If
-
End If
-
End If
-
With Reports![rpt1]
-
.Filter = strFilter
-
.FilterOn = True
-
.OrderBy = strSortOrder
-
.OrderByOn = True
-
End With
-
End Sub
-
-
_______________________________________________________
-
Private Sub cmdApplyFilter_Click()
-
On Error GoTo Err_cmdApplyFilter_Click
-
-
Dim stDocName As String
-
-
stDocName = "rpt1"
-
DoCmd.OpenReport stDocName, acPreview
-
-
Exit_cmdApplyFilter_Click:
-
Exit Sub
-
-
Err_cmdApplyFilter_Click:
-
MsgBox Err.Description
-
Resume Exit_cmdApplyFilter_Click
-
-
End Sub
-
-
Dim Response As VbMsgBoxResult
-
If SysCmd(acSysCmdGetObjectState, acReport, "rpt1") <> acObjStateOpen Then
-
Response = MsgBox("The report is not open." _
-
& vbCrLf & "Do you want to open it now?" _
-
, vbQuestion + vbYesNoCancel)
-
SelectCase Response
-
Case vbYes
-
DoCmd.OpenReport "rpt1", acViewPreview
-
Case vbNo
-
Exit Sub
-
Case vbCancel
-
DoCmd.Close acForm, Me.Name
-
Exit Sub
-
End Select
-
End If
6 1966
Please let us know what exactly is occurring and what tests you have done so far - 'It isn't opening like it should' does not help us to help you at all.
-Stewart
The error message (by MS Access Assistant)reads as follows:
*The expression may not result in the name of a macro, the name of a user-defined funtion, or [Event Procedure].
*There may have been an error evaluating the funtion,event,or macro What should happen: When you click Apply Filter it should check for the open report. If a report isn't open it should ask it the person would like to open it. If yes then report should open. and the run filter. What happens: I click Apply Filter and receive the error message. What I have done: As far as "test" go nothing. What test can I do? I have however read over the codes many times and as far as I can see it should work. I have also checked the reoprt name. See I am still fig. out about coding so I used templates to do this. The first have works but when I added the secound half it gave me the error message.
What you need to do is to set a breakpoint at the start of the Apply_Filter routine (around line 9 above, say), then single-step through each line of code until you come to the line which causes the failure you mention.
Until we know which one is failing we'd just be guessing at present.
We have an Insights article on debugging in VBA which you may find useful. The overview is linked here for you.
-Stewart
I don't know what a breakpoint is. however I think I fig. it out. I just had it open the report auto w/o checking or asking.
But for more knowlege I would still love to know how to set a breakpoint. Can you show me what it would look like? Thank you.
See link and image below for Breakpoint in VBA
but you can also use msgbox to troubleshoot, by placing it ... let's say in the middle of your script and see if the problem occurs before or after the message box pops up http://www.learnaccessnow.com/chap20d.html
Thank you for all your help
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Wayfarer |
last post by:
I am using Microsoft Access 2000.
I am designing a report using an aggregate query parameterized on a
date range. I am using a form for users to select the range, allowing
"First Quarter 2005"...
|
by: charles_weaver |
last post by:
I create a Code Comment Web Report for a C# ( or C++) project. All of
the files are there, one for each method. But when I run the meain page
it doesn't seem to hook together. I get to the page...
|
by: Greg |
last post by:
Hello,
I'm about to write a database application and I'm wondering
how to approach it. Is it worth to use the database code auto-generation
(VC# 2005) in the long run? Or at some point I'll be...
|
by: hb |
last post by:
Hi,
The auto-formatting of HTML code in Visual Studio.Net 2003 is very annoying!
I already unchecked the 2 checkboxes in "Apply Automatic Formatting" section
located at:
Tools-->Options-->Text...
|
by: Andreas |
last post by:
Hi there!
The splendid Code Comment Web Report is only available in
C#. I request it in VB.net.
The documentation states:
"Currently, only C# supports the code comment syntax
required for...
|
by: Miguel |
last post by:
I have reviewed the many postings on this topic and understand the
principle, but am not sure where in my case to apply trapping an error.
I have created a form to supply parameters to a report. I...
|
by: Scott |
last post by:
Hello-
I have a contol button on a form that I want to code to open a report
(rptReviews), then display the print dialogue box so that users can
select a printer. This report needs color, but...
|
by: martin DH |
last post by:
Hello,
I have a report that I open that pull its data from a form that builds a where string. Opening the report first opens the form, where I enter criteria, and then pulls matching records from a...
|
by: Phil Stanton |
last post by:
I am opening a report (in Preview) from a menu system
I use the following code if there is no data in a report
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There are no errors in...
|
by: pacarv |
last post by:
I've created a database in Access 2003 with multiple reports that are accessable from the switchboard. The switchboard also has a print button. The user selects the report from the menu which then...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |