|
-
Oct 9th, 2002, 11:16 AM
#1
Thread Starter
Lively Member
Passing forms to classes...
Hello, I'm just getting into Object based Programming (with VB6, which I have to use at work for now - .NET later, hopefully soon).
Here's the situation: I'm trying to encapsulate code for populating combo boxes throughout in a multiform project. I have made a class called, surprisingly, "populateCombo". Here is the code I have so far in that class module (just one method):
Public Sub populateCombo(ByVal frmWhich As Integer, ByVal cboNum As Integer, ByVal tblName As String, fieldName As String)
Dim objRS As New ADODB.Recordset
Dim strSQL As String
strSQL = "SELECT " & fieldName & " FROM " & tblName & ";"
objRS.Open strSQL, g_objConn, adOpenForwardOnly, adLockReadOnly
If frmWhich = 0 Then
Do While Not objRS.EOF
frm1.Combo(cboNum).AddItem objRS.Fields(fieldName)
objRS.MoveNext
Loop
Set objRS = Nothing
ElseIf frmWhich = 1 Then
Do While Not objRS.EOF
frm2.Combo1(0).AddItem objRS.Fields(fieldName)
objRS.MoveNext
Loop
Set objRS = Nothing
End If
End Sub
It's pretty self-explanatory, but the if-then structures sort of defeat the purpose of reusable code. Is there a way to pass in form names when I call populateCombo rather than having the frmWhich and repeating the code for each form? The current configuration works fine, but I'd like to make it slicker, for example, when I call the procedure I'd like to do something like this: Call populateCombo("frm1", 1, "<table name>", "<field name>"). Is this even possible or am I stuck with the above situation?
Thank you! This forum has been a big help to me!
Ed Womack
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|