VBA: Compile Error ByRef Argument Type Mismatch in Private Sub

102 views Asked by At

I consistently get the Compile Error: ByRef Argument type mismatch for (myQuarterNo).

error screenshot

I'll include the module that gives QuarterName value. The goal is to have "Quarter1", "Quarter2", "Quarter3", or "Quarter4" be displayed in the specified text box. Similar to how a MonthName would. I can also include the frmQuarterlyExciseInput if needed.

It is probably something simple that I am overlooking. If more info is needed, please ask. The entirety of the code with the error is incredibly long so i only included the relevant block. I can always post more of it.

Code With Error:

Option Compare Database
Option Explicit


Dim intReportVersion As Integer
Dim myQuarterNo As String
Dim myYear As Integer
Dim myStartDate As String
Dim myBottleConvertValue As Double


Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim myDate
Dim myQuarterName As String
Dim myYear As Integer
Dim dblLine13Gallons As Double
Dim dblLine15Gallons As Double
Dim dblLine21Gallons As Double
Dim dblLine22Gallons As Double
Dim dblLine24Gallons As Double
Dim dblLine25Gallons As Double
Dim dblLine26Gallons As Double
Dim dblLine27Gallons As Double
Dim dblLine29Gallons As Double
Dim dblLine30Gallons As Double
Dim dblLine31Gallons As Double
Dim dblLine32Gallons As Double
Dim dblLine33Gallons As Double
Dim dblLine34Gallons As Double
Dim dblLine35Gallons As Double
Dim dblLine37StateWineTax As Double
    

        myQuarterNo = [Forms]![frmQuarterlyExciseInput]![cboquarter]
        myQuarterName = QuarterName(myQuarterNo)
        myYear = [Forms]![frmQuarterlyExciseInput]![cboCurrentYear]
        Me.txtQuarterName = myQuarterName
        Me.txtYear = myYear
        
        ' ok lets to the fetching and calculating
        dblLine13Gallons = Round(CalculateLine13Gallons(myBottleConvertValue), 2)
        dblLine15Gallons = Round(CalculateLine15Gallons(myBottleConvertValue), 2)
        dblLine21Gallons = Round(dblLine13Gallons + dblLine15Gallons, 2)
        dblLine30Gallons = Round(CalculateLine30Gallons(myBottleConvertValue), 2) 'Out of stste include NULL stste
        'Line 30 moved to calculate so as to add to line 24
        dblLine24Gallons = Round(CalculateLine24Gallons(myBottleConvertValue), 2) + dblLine30Gallons
        dblLine25Gallons = Round(CalculateLine25Gallons(myBottleConvertValue), 2)
        dblLine26Gallons = Round(CalculateLine26Gallons(myBottleConvertValue), 2)
        dblLine27Gallons = Round(CalculateLine27Gallons(myBottleConvertValue), 2) ' Ship in MD no NULL stste
        'Added line 27 7/7/2020
        '7/24/20 Now to be reported on line 30.A
        dblLine29Gallons = Round(CalculateLine29Gallons(myBottleConvertValue), 2)

        dblLine31Gallons = Round(CalculateLine31Gallons(myBottleConvertValue), 2)
        dblLine32Gallons = Round(CalculateLine32Gallons(myBottleConvertValue), 2)
        dblLine33Gallons = Round(CalculateLine33Gallons(myBottleConvertValue), 2)
        dblLine34Gallons = Round(CalculateLine34Gallons(myBottleConvertValue), 2)
        dblLine22Gallons = Round(dblLine21Gallons - (dblLine24Gallons + dblLine25Gallons + dblLine26Gallons + dblLine27Gallons + dblLine29Gallons + dblLine31Gallons + dblLine32Gallons + dblLine33Gallons + dblLine34Gallons), 2)
        ' 7/24/20 dblLine30Gallons removed to avoid double count because dblLine30Gallons is now in line 24
        dblLine37StateWineTax = DLookup("SetUpValue", "DbSetup", "SetupKey='STATEWINETAX'")
        dblLine35Gallons = Round(dblLine22Gallons + dblLine24Gallons + dblLine25Gallons + dblLine26Gallons + dblLine27Gallons + dblLine29Gallons + dblLine31Gallons + dblLine32Gallons + dblLine33Gallons + dblLine34Gallons, 2)
        ' 7/24/20 dblLine30Gallons removed to avoid double count because dblLine30Gallons is now in line 24
        
        ' ok now put the data onto the form
        Me.txtLine13 = Round(dblLine13Gallons, 2)
        Me.txtLine15 = Round(dblLine15Gallons, 2)
        Me.txtLine21 = Round(dblLine21Gallons, 2)
        Me.txtLine24 = Round(dblLine24Gallons, 2)
        '7/24/20 Now line 24 includes former line 30 data
        Me.txtLine25 = Round(dblLine25Gallons, 2)
        Me.txtLine26 = Round(dblLine26Gallons, 2)
        Me.txtLine27 = Round(dblLine27Gallons, 2)
        ' Added line 27 7/7/2020 will be reported on line 30A
        Me.txtLine29 = Round(dblLine29Gallons, 2)
        Me.txtLine30 = 0 'Round(dblLine30Gallons, 2) deleted, now included on line 24
        Me.txtLine31 = Round(dblLine31Gallons, 2)
        Me.txtLine32 = Round(dblLine32Gallons, 2)
        Me.txtLine33 = Round(dblLine33Gallons, 2)
        Me.txtLine34 = Round(dblLine34Gallons, 2)
        Me.txtLine22 = Round(dblLine22Gallons, 2)
        Me.txtLine35 = Round(dblLine35Gallons, 2)
        ' need to add/test for line 34. If Not Null AND is > 0, add it to the line 36 formula below.
        If (dblLine34Gallons > 0) Then
            Me.txtLine36 = Round(dblLine31Gallons + dblLine32Gallons + dblLine33Gallons + dblLine34Gallons, 2)
        Else
            Me.txtLine36 = Round(dblLine31Gallons + dblLine32Gallons + dblLine33Gallons, 2)
        End If
        Me.txtLine37 = dblLine37StateWineTax
        Me.txtLine38 = Round(dblLine37StateWineTax * CDbl(Me.txtLine36), 2)
        If (IsNull([Forms]![frmQuarterlyExciseInput]![txtPrepaidWineTax]) = False) Then
            Me.txtLine39 = [Forms]![frmQuarterlyExciseInput]![txtPrepaidWineTax]
        Else
            Me.txtLine39 = 0
        End If
        Me.txtLine40 = CDbl(Me.txtLine38) - CDbl(Me.txtLine39)
End Sub

Module that shows QuarterName:

Option Compare Database
Option Explicit

Public Function QuarterName(varQuarter As Integer, varYear As Integer) As String
      Select Case varQuarter
    Case 1
        strDateString = " [Invoices].[TransactionDate] Between #01/01/" & varYear & "# AND #03/31/" & varYear & "# "
    Case 2
        strDateString = " [Invoices].[TransactionDate] Between #04/01/" & varYear & "# AND #06/30/" & varYear & "# "
    Case 3
        strDateString = " [Invoices].[TransactionDate] Between #07/01/" & varYear & "# AND #09/30/" & varYear & "# "
    Case 4
        strDateString = " [Invoices].[TransactionDate] Between #10/01/" & varYear & "# AND #12/31/" & varYear & "# "
    End Select
    QuarterName = strDateString

End Function
1

There are 1 answers

1
ashleedawg On

Your function QuarterName appears to require 2 arguments (Quarter and varYear), both integers.

It looks like you're giving it 1 argument: probably a string (which is how form data is generally returned).

You might have more luck if you figure out the 2nd argument, and convert strings to integers with CInt if necessary. (See Microsoft's list of "Type Conversion Functions".)

Also note that, when debugging, you can also check what data type a variable or expression is currently stored in, using TypeName.

See also, VBA Data Types.


Unrelated side note, when you see a lot of repetition in code, it might be time to rethink your approach -- for example, perhaps using an array instead of all the dblLineXXGallons variables