Home All Groups Group Topic Archive Search About
Author
9 May 2007 2:02 PM
Darhl Thomason
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

Author
9 May 2007 3:57 PM
Jan Hyde (VB MVP)
"Darhl Thomason" <darhlt@papamurphys.nospamplease.com>'s
wild thoughts were released on Wed, 9 May 2007 07:02:58
-0700 bearing the following fruit:

Show quoteHide quote
>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.
Author
9 May 2007 5:35 PM
Darhl Thomason
"Jan Hyde (VB MVP)" <StellaDrin***@REMOVE.ME.uboot.com> wrote in message
news:1kr3435aqhdqjcq90drbqht6u4g5ltkq2q@4ax.com...
>
> 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.
>
>
OK, I added an error handler, and the error is definitely in the calling
line.

When I put a breakpoint on every line in the sub and on the calling line, it
stops on the calling line as expected, and when I tell it to proceed is when
it throws the error, it never makes to the routine.  The sub that contains
the calling line also has an error handler and is definitely what is
generating the error.  My routine now looks like:

Private Sub setComboRS(cbo As ComboBox, strData As String, strList As
String, strTable As String)
On Error GoTo err_setComboRS
  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
Exit Sub
err_setComboRS:
  MsgBox Err.Number & " " & Err.Description, , "setComboRS"
End Sub
Author
9 May 2007 5:48 PM
Darhl Thomason
Show quote Hide quote
"Darhl Thomason" <darhlt@papamurphys.nospamplease.com> wrote in message
news:u5BmuBmkHHA.1624@TK2MSFTNGP06.phx.gbl...
>
> "Jan Hyde (VB MVP)" <StellaDrin***@REMOVE.ME.uboot.com> wrote in message
> news:1kr3435aqhdqjcq90drbqht6u4g5ltkq2q@4ax.com...
>>
>> 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.
>>
>>
> OK, I added an error handler, and the error is definitely in the calling
> line.
>
> When I put a breakpoint on every line in the sub and on the calling line,
> it stops on the calling line as expected, and when I tell it to proceed is
> when it throws the error, it never makes to the routine.  The sub that
> contains the calling line also has an error handler and is definitely what
> is generating the error.  My routine now looks like:
>
> Private Sub setComboRS(cbo As ComboBox, strData As String, strList As
> String, strTable As String)
> On Error GoTo err_setComboRS
>  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
> Exit Sub
> err_setComboRS:
>  MsgBox Err.Number & " " & Err.Description, , "setComboRS"
> End Sub
>
>
OK, more info, I pulled the cbo as ComboBox from the sub declaration, and
updated the sub with the name of the combo box, so it appears that is what
it doesn't like.  Shouldn't I be able to pass the name of a combo box into
the sub?

Thanks,

d
Author
9 May 2007 6:35 PM
Ralph
Show quote Hide quote
"Darhl Thomason" <darhlt@papamurphys.nospamplease.com> wrote in message
news:O4bvDJmkHHA.568@TK2MSFTNGP02.phx.gbl...
>
> "Darhl Thomason" <darhlt@papamurphys.nospamplease.com> wrote in message
> news:u5BmuBmkHHA.1624@TK2MSFTNGP06.phx.gbl...
> >
> > "Jan Hyde (VB MVP)" <StellaDrin***@REMOVE.ME.uboot.com> wrote in message
> > news:1kr3435aqhdqjcq90drbqht6u4g5ltkq2q@4ax.com...
> >>
> >> 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.
> >>
> >>
> > OK, I added an error handler, and the error is definitely in the calling
> > line.
> >
> > When I put a breakpoint on every line in the sub and on the calling
line,
> > it stops on the calling line as expected, and when I tell it to proceed
is
> > when it throws the error, it never makes to the routine.  The sub that
> > contains the calling line also has an error handler and is definitely
what
> > is generating the error.  My routine now looks like:
> >
> > Private Sub setComboRS(cbo As ComboBox, strData As String, strList As
> > String, strTable As String)
> > On Error GoTo err_setComboRS
> >  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
> > Exit Sub
> > err_setComboRS:
> >  MsgBox Err.Number & " " & Err.Description, , "setComboRS"
> > End Sub
> >
> >
> OK, more info, I pulled the cbo as ComboBox from the sub declaration, and
> updated the sub with the name of the combo box, so it appears that is what
> it doesn't like.  Shouldn't I be able to pass the name of a combo box into
> the sub?
>
> Thanks,
>
> d
>

Are you sure it is "ComboBox"?

-ralph
Author
9 May 2007 6:53 PM
Darhl Thomason
Show quote Hide quote
"Ralph" <nt_consultin***@yahoo.com> wrote in message
news:hc2dnR2snNYYid_bnZ2dnUVZ_uiknZ2d@arkansas.net...
>
>> > OK, I added an error handler, and the error is definitely in the
>> > calling
>> > line.
>> >
>> > When I put a breakpoint on every line in the sub and on the calling
> line,
>> > it stops on the calling line as expected, and when I tell it to proceed
> is
>> > when it throws the error, it never makes to the routine.  The sub that
>> > contains the calling line also has an error handler and is definitely
> what
>> > is generating the error.  My routine now looks like:
>> >
>> > Private Sub setComboRS(cbo As ComboBox, strData As String, strList As
>> > String, strTable As String)
>> > On Error GoTo err_setComboRS
>> >  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
>> > Exit Sub
>> > err_setComboRS:
>> >  MsgBox Err.Number & " " & Err.Description, , "setComboRS"
>> > End Sub
>> >
>> >
>> OK, more info, I pulled the cbo as ComboBox from the sub declaration, and
>> updated the sub with the name of the combo box, so it appears that is
>> what
>> it doesn't like.  Shouldn't I be able to pass the name of a combo box
>> into
>> the sub?
>>
>> Thanks,
>>
>> d
>>
>
> Are you sure it is "ComboBox"?
>
> -ralph
>
>

Good question Ralph, when I look at the ComboBox on my form, I see it is
really a "DataCombo", I'll try that...

And that was the issue!  My sub now is:

Private Sub setComboRS(cbo As DataCombo, strData As String, strList As
String, strTable As String)
On Error GoTo err_setComboRS
  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
Exit Sub
err_setComboRS:
  MsgBox Err.Number & " " & Err.Description, , "setComboRS"
End Sub

and it works like a charm.  Thanks Ralph & Jan!

Darhl