Lorthas
Lorthas

Reputation: 376

Possible syntax mistake? "Expecting =" In a Sub call from a UserForm

I want to call a Sub I declared at it gives a compilation error saying that it expects a =. The Sub call is in a UserForm_Initialize event procedure. The code is as follows.

In a module:

Public Sub FillCb(Ar() As String, Cb As ComboBox)
    Cb.Clear
    For I = 1 To Application.CountA(Ar)
        Cb.AddItem (Ar(I))
    Next I
End Sub

In the UserForm code:

Private Sub UserForm_Initialize()
    LblDate.Caption = Date
    FillCb(LibrosNoPrestados, CbLibro)
End Sub

This code is giving me error. I analized the code line by line using the debugger and commenting the las line inside the Initialize event, and it works fine up to that point. The error is thrown at compile time in the

FillCb(LibrosNoPrestados, CbLibro)

The rest of the code is not needed here since as I said it works fine, but the syntax in that last line must be wrong and I can't see the mistake.

Upvotes: 0

Views: 53

Answers (1)

ACCtionMan
ACCtionMan

Reputation: 511

A VBA "feature". If you are calling a sub routine without the "Call" keyword then don't use parentheses, if you use the "Call" keyword then you need the parentheses.

Eg Call FillCb(LibrosNoPrestados, CbLibro)

Or

FillCb LibrosNoPrestados, CbLibro

Here's Microsoft's documentation: https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/call-statement

Upvotes: 1

Related Questions