tags:

views:

53

answers:

2

I am able to add controls to a form when it is loaded. I need these controls to be to be catagorized so the user only can see a few at a time. My first thought was to attached the controls to particular tabs. Not sure why the syntax is off in the following code. Thanks for the help!

Private Sub Enter_Records_Click()

Dim stDocName As String
Dim tabPage As String
Dim tabNum As Integer
Dim i As Integer
Dim passedTabName As String

stDocName = "CLForm"
tabPage = "tabControl.tabPage"
stTabName = stDocName & tabPage
tabNum = 8 'the number of tabs on the "CLForm"

DoCmd.OpenForm stDocName, acDesign
For i = 0 To tabNum - 1
    passedTabName = stTabName & i
    CreateKeywords (stDocName, passedTabName)
Next i
DoCmd.Close acForm, stDocName, acSaveYes
DoCmd.OpenForm stDocName, acNormal

End Sub

Public Sub CreateKeywords(frmName As String, tabName As String)

Another idea that might be better, simply having buttons that show one category of controls at a time. Would this be easier?

+2  A: 

You need to use the Call keyword when calling a method with more than one parameter and using parentheses.

For example, these would work:

Call CreateKeywords(stDocName, passedTabName)
CreateKeywords stDocName, passedTabName
//Example of using parentheses with one parameter
Msgbox (stDocName) 

Welcome to the wonderful world of VBA. ;)

voon
Or simply omit the parentheses: CreateKeywords stDocName, passedTabName
Remou
A: 

It is best be careful with calling arguments and parentheses:

Public Sub CallingSub()
   CallingArg = "ABCDEF"
   CalledFunc CallingArg
   Debug.Print CallingArg ''Result: 987654

   CallingArg = "ABCDEF"
   CalledFunc (CallingArg) ''Result: ABCDEF
   Debug.Print CallingArg

   CallingArg = "ABCDEF"
   Call CalledFunc(CallingArg)
   Debug.Print CallingArg ''Result: 987654
End Sub

Public Function CalledFunc(CalledFuncArg)
   CalledFuncArg = "987654"
   CalledFunc = "Return"
End Function
Remou
Isn't this more a caution for using ByRef? Basically, while ByRef is the default in VBA for passing parameters, you should really only use it when you are certain that you want the ability to modify the passed variable within the called sub/function.
David-W-Fenton