Archana
Archana

Reputation: 37

Error VBA function

Function CC1(BP As short, CC As short) As String
    If BP = 1 Then
    cc = "B*"
      Else
    cc = "C*"
   End If
End Function

I tried to call the above function in access query, but if says compile error

Access query has this function in below format

n: CC1([BP],[CC])

Upvotes: 1

Views: 65

Answers (3)

Santosh
Santosh

Reputation: 12353

Byte is suitable for your function defined

SELECT CC1([BP],[CC]) as n

Function CC1(BP As Byte, CC As Byte) As String
    If BP = 1 Then
    CC1 = "B*"
      Else
    CC1 = "C*"
   End If
End Function

Note:

  1. The value to be returned must be assigned to a variable having the same name as the Function
  2. CC As Byte is not used.

Upvotes: 0

QHarr
QHarr

Reputation: 84465

As mentioned Short doesn't exist.

Declare as Long which can easily cater for signed 16-bit (2-byte) integers that range in value from -32,768 through 32,767.

Why Long? See the lengthy discussion here: Why Use Integer Instead of Long?

Upvotes: 1

Andre
Andre

Reputation: 27644

VBA doesn't have a data type short.

https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/data-type-summary

Upvotes: 2

Related Questions