Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Invalid procedure call or argument

Posted on 2016-09-30
1
Medium Priority
?
76 Views
Last Modified: 2016-10-04
I have a form with a command button that opens a report.  If I just open the form and make no changes to the data the report opens just fine.  But if I make a change to the data in the form and click the command button to open the report I get an error...  "Invalid procedure call or argument"

Here is the onclick event of the command button.  Any thoughts?

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

    Dim stDocName As String

    strQD = "" '< clear the variable first
    

    If Me.lstPartNChills.ListCount >= 1 Then
        Dim j
        With lstPartNChills
        For j = 1 To .ListCount - 1
        strQD = strQD & "(" & .Column(1, j) & ") - " & .Column(2, j) & ", "
        Next
        End With
        strQD = Left(strQD, Len(strQD) - 2)
    End If

    stDocName = "rptProcessCard"
    DoCmd.OpenReport stDocName, acPreview
    
    strQD = ""

Open in new window

0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 22

Accepted Solution

by:
crystal (strive4peace) - Microsoft MVP, Access earned 2000 total points
ID: 41823697
instead of: DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
do:
if me.dirty then me.dirty=false

Open in new window

which will save the record only if changes have been made.
For constructing the where clause, use null propogation (+ to concatenate in a comma only if something is already there):
dim vWhere as variant
vWhere = Null

Open in new window

then in the loop:
vWhere  =( vWhere  + ", ") & ...

Open in new window

can you give an example of what you want? I see you are doing math but realize that columns of a list or combo are text and need to be wrapped in a conversion function to get a number.  Or are you trying to get a range of values?

When you open the report, specify the where clause to limit the records
    DoCmd.OpenReport stDocName, acPreview , , vWhere

Open in new window

0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question