Search code examples
vb6ms-access-2010

"Compile Error: Only Comments may appear after End Sub, End Function.." Access 2010 VBA


I am creating a form and I have created my first function in the VBA window. The function creates Buttons. After I type anything after the 'End function' I get an error- "Only comments appear after .." What's wrong? Am I putting the function in the wrong area?

Here is my code:

Option Compare Database 
Option Explicit

Function MainMenuOptions()

Dim frm As String
frm = "Main"

Dim SCFormB As Control
Dim SCSearchB As Control
Dim SCReportB As Control

Set SCFormB = CreateControl(frm, acOptionButton, , , , 0.5, 0.6, 1.5, 0.55)
Set SCSearchB = CreateControl(frm, acOptionButton, , , , 0.5, 1.5, 1.5, 0.55)
Set SCReportB = CreateControl(frm, acOptionButton, , , , 0.5, 2.4, 1.5, 0.55)


End Function

Solution

  • Apparently, you have extra code in your module which is outside of a function or sub. In the VBA editor select debug -> compile and it should highlight the offending code which you can remove or revise.

    FYI: CreateControl uses twips(one 1440th of an inch) for left, top, width, and height. You may want to multiply the numbers you are using by about 1440.