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
精彩评论