Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 87
  • Last Modified:

Invalid procedure call or argument

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
SteveL13
Asked:
SteveL13
1 Solution
 
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now