Re: Type mismatch error

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"Darhl Thomason" <darhlt@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>'s
wild thoughts were released on Wed, 9 May 2007 07:02:58
-0700 bearing the following fruit:

I am working on doing some code consolidation. Larry S helped me a little a
few months ago, but I haven't been able to work on it 'til now (where does
the time go?)

I currently have this:

Set adoStatusRS = New Recordset
adoStatusRS.Open "SELECT StatusName, StatusID from tblStatus ORDER BY
StatusID", db, adOpenStatic, adLockOptimistic
With cboStatus
.DataField = "StatusID"
.BoundColumn = "StatusID"
.ListField = "StatusName"
Set .RowSource = adoStatusRS
Set .DataSource = adoPrimaryRS
End With
Set adoFpmRS = New Recordset
adoFpmRS.Open "SELECT FpmName, FpmID from tblFpm ORDER BY FpmName", db,
adOpenStatic, adLockOptimistic
With cboFpm
.DataField = "FpmID"
.BoundColumn = "FpmID"
.ListField = "FpmName"
Set .RowSource = adoFpmRS
Set .DataSource = adoPrimaryRS
End With
Set adoDfoRS = New Recordset
adoDfoRS.Open "SELECT FCName, FCID from tblFC ORDER BY FCName", db,
adOpenStatic, adLockOptimistic
With cboDfo
.DataField = "FCID"
.BoundColumn = "FCID"
.ListField = "FCName"
Set .RowSource = adoDfoRS
Set .DataSource = adoPrimaryRS
End With

I want to consolidate this because I know there's tons of repetition there
that I'm sure I can trim down.

Here's what I want to end up with:

Private Sub setComboRS(cbo As ComboBox, strData As String, strList As
String, strTable As String)
Dim rs As Recordset
Set rs = New Recordset
rs.Open "SELECT " & strList & ", " & strData & " from " & strTable & "
ORDER BY " & strList, db, adOpenStatic, adLockOptimistic
With cbo
.DataField = strData
.BoundColumn = strData
.ListField = strList
Set .RowSource = rs
Set .DataSource = adoPrimaryRS
End With
End Sub

and call it by:

Call setComboRS(cboDfo, "FCID", "FCName", "tblFC")
or by
setComboRS cboDfo, "FCID", "FCName", "tblFC"

but both ways give me a type mismatch on the calling line. When I step
through the code, it never makes it to the new sub...

Thanks for any help!

Darhl

Make sure you have an error handler in your routine then it
will be clear to you if the error lies in the routine or in
the way you are calling ti.



.


Quantcast