开发者

Access VBA 2007 passing a form as a parameter

开发者 https://www.devze.com 2023-02-03 20:29 出处:网络
We are trying to reduce duplicate code in our access database. We have severalfo开发者_开发技巧rms what we use the following sort of code on.

We are trying to reduce duplicate code in our access database. We have severalfo开发者_开发技巧rms what we use the following sort of code on.

strSQL = "Some SQL"
Me!cboClientName.RowSource = strSQL
Me!cboClientName.BoundColumn = 2
Me!cboClientName.ColumnCount = 2
Me!cboClientName.ColumnWidths = "0cm ; 2 cm"

What I wanted to do is create a sub routine and pass the form into it and then replace the Me with the object.

So I now have something like this:

Public Sub subName(myForm as Form)
    strSQL = "SELECT [tblClients].[ID], [tblClients].[ClientName] FROM [tblClients] ORDER BY [ClientName]"
    myForm !cboClientName.RowSource = strSQL
    myForm !cboClientName.BoundColumn = 2
    myForm !cboClientName.ColumnCount = 2
    myForm !cboClientName.ColumnWidths = "0cm ; 2 cm"

cboClientName is on every form that I am calling it on. I then am calling the sub routine using.

subName(Me)

I am however getting the error:

Type mis match ... 13

What am I doing wrong? Is there a better way todo this?


That should be

 subName Me

No brackets.

Further information: http://msdn.microsoft.com/en-us/library/gg251710.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消