derohanes
05-14-2007, 11:58 AM
I am curious about what is expected of the combo control. I am using cbo variable to load the control. The question I have is in the declaration of the control. I have successfully loaded a combo box with data from a db using .additem after the cbo variable without declaring it. I forgot to dimension that, but it works. I don't understand why though. In another sub I use another cbo variable and I get errors. If I don't DIM it I get a "Variable not defined error" if I do DIM it I get an "Invalid qualifier" error. Any ideas?
I am trying to load the combo box from an Access DB then using the selection to pull that record. In the section I am having problems with, "Private Sub cmdEditToolForm_Click()", "cboEditTool.additem" is the problem. In the "Private Sub Form_Load()" section of the code, "cboToolSizeFrom.AddItem" has no problems.
I am incrementally adding buttons as I develop application. It worked through to the point of reading the DB, and adding to the DB, but I'm having trouble reading in the section where I want to edit.
This is partial code, to save space, but the application has a main form, from which I select a tool size, and do some calculations on it. That main form can launch 2 others using command buttons. One adds to the DB, which works. The other should load the combo box with available tools in the DB, I select a tool and it populates boxes for editing. That portion is not complete, because I'm stuck on populating the combo box because of this error.
Code:
Option Explicit
Public booIsAdding As Boolean
Public cn As ADODB.Connection
Public rs As ADODB.Recordset
Dim strSQL As String
'Test portion*************
Dim txtTestSize As String
Dim sngTestArea As Single
Dim sngTestLength As Single
Dim strToolInitial As String
Dim strToolTarget As String
Dim strEditToolDimension As String, strEditShape As String, strSQL_Insert As String, strEditHobNumber As String
Dim sngEditCupDepth As Single, sngEditCupVolume As Single, sngEditDieArea As Single
Dim sngEditCupSurfaceArea As Single
Dim cboEditTool As String
Dim strAddToolDimension As String
Dim sngAddCupDepth As Single, sngAddCupVolume As Single, sngAddDieArea As Single
Private Sub cmdAddToolForm_Click()
frmAddTool.Left = (Screen.Width - frmAddTool.Width) * 2 / 3
frmAddTool.Top = (Screen.Height - frmAddTool.Height) * 2 / 3
frmAddTool.Show
End Sub
Private Sub cmdEditToolForm_Click()
'On Error GoTo errHandler_DB
strSQL = "SELECT * FROM tblSizes"
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=tooling.mdb"
cn.Open
Set rs = New ADODB.Recordset 'as we did with the connection
rs.Open strSQL, cn, adOpenKeyset, adLockPessimistic, adCmdText
rs.MoveFirst 'moves to the first record
Do Until rs.EOF = True 'this is the Loop to add items to the combo box
cboEditTool.AddItem rs.Fields("Dimensions") 'this adds items from field1 into the combo box
rs.MoveNext 'moves next record
Loop
rs.MoveFirst
fillfieldDimensions 'i'll explain this later on.
Me.MousePointer = 0 'sets the mouse pointer to the normal arrow
rs.Close
frmEditTool.Left = (Screen.Width - frmEditTool.Width) * 2 / 3
frmEditTool.Top = (Screen.Height - frmEditTool.Height) * 2 / 3
frmEditTool.Show
End Sub
Private Sub Form_Load()
reset
frmToolingTest.Left = (Screen.Width - frmToolingTest.Width) / 2
frmToolingTest.Top = (Screen.Height - frmToolingTest.Height) / 2
strSQL = "SELECT * FROM tblSizes"
Me.MousePointer = 11 'this makes the mouse pointer the hourglass
Set cn = New ADODB.Connection 'we've declared it as a ADODB connection lets set it.
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=tooling.mdb"
cn.Open
Set rs = New ADODB.Recordset 'as we did with the connection
rs.Open strSQL, cn, adOpenKeyset, adLockPessimistic, adCmdText
rs.MoveFirst 'moves to the first record
Do Until rs.EOF = True 'this is the Loop to add items to the combo box
cboToolSizeFrom.AddItem rs.Fields("Dimensions") 'this adds items from field1 into the combo box
cboToolSizeTo.AddItem rs.Fields("Dimensions") 'this adds items from field1 into the combo box
rs.MoveNext 'moves next record
Loop
rs.MoveFirst
fillfieldDimensions 'i'll explain this later on.
Me.MousePointer = 0 'sets the mouse pointer to the normal arrow
rs.Close
End Sub
I am trying to load the combo box from an Access DB then using the selection to pull that record. In the section I am having problems with, "Private Sub cmdEditToolForm_Click()", "cboEditTool.additem" is the problem. In the "Private Sub Form_Load()" section of the code, "cboToolSizeFrom.AddItem" has no problems.
I am incrementally adding buttons as I develop application. It worked through to the point of reading the DB, and adding to the DB, but I'm having trouble reading in the section where I want to edit.
This is partial code, to save space, but the application has a main form, from which I select a tool size, and do some calculations on it. That main form can launch 2 others using command buttons. One adds to the DB, which works. The other should load the combo box with available tools in the DB, I select a tool and it populates boxes for editing. That portion is not complete, because I'm stuck on populating the combo box because of this error.
Code:
Option Explicit
Public booIsAdding As Boolean
Public cn As ADODB.Connection
Public rs As ADODB.Recordset
Dim strSQL As String
'Test portion*************
Dim txtTestSize As String
Dim sngTestArea As Single
Dim sngTestLength As Single
Dim strToolInitial As String
Dim strToolTarget As String
Dim strEditToolDimension As String, strEditShape As String, strSQL_Insert As String, strEditHobNumber As String
Dim sngEditCupDepth As Single, sngEditCupVolume As Single, sngEditDieArea As Single
Dim sngEditCupSurfaceArea As Single
Dim cboEditTool As String
Dim strAddToolDimension As String
Dim sngAddCupDepth As Single, sngAddCupVolume As Single, sngAddDieArea As Single
Private Sub cmdAddToolForm_Click()
frmAddTool.Left = (Screen.Width - frmAddTool.Width) * 2 / 3
frmAddTool.Top = (Screen.Height - frmAddTool.Height) * 2 / 3
frmAddTool.Show
End Sub
Private Sub cmdEditToolForm_Click()
'On Error GoTo errHandler_DB
strSQL = "SELECT * FROM tblSizes"
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=tooling.mdb"
cn.Open
Set rs = New ADODB.Recordset 'as we did with the connection
rs.Open strSQL, cn, adOpenKeyset, adLockPessimistic, adCmdText
rs.MoveFirst 'moves to the first record
Do Until rs.EOF = True 'this is the Loop to add items to the combo box
cboEditTool.AddItem rs.Fields("Dimensions") 'this adds items from field1 into the combo box
rs.MoveNext 'moves next record
Loop
rs.MoveFirst
fillfieldDimensions 'i'll explain this later on.
Me.MousePointer = 0 'sets the mouse pointer to the normal arrow
rs.Close
frmEditTool.Left = (Screen.Width - frmEditTool.Width) * 2 / 3
frmEditTool.Top = (Screen.Height - frmEditTool.Height) * 2 / 3
frmEditTool.Show
End Sub
Private Sub Form_Load()
reset
frmToolingTest.Left = (Screen.Width - frmToolingTest.Width) / 2
frmToolingTest.Top = (Screen.Height - frmToolingTest.Height) / 2
strSQL = "SELECT * FROM tblSizes"
Me.MousePointer = 11 'this makes the mouse pointer the hourglass
Set cn = New ADODB.Connection 'we've declared it as a ADODB connection lets set it.
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=tooling.mdb"
cn.Open
Set rs = New ADODB.Recordset 'as we did with the connection
rs.Open strSQL, cn, adOpenKeyset, adLockPessimistic, adCmdText
rs.MoveFirst 'moves to the first record
Do Until rs.EOF = True 'this is the Loop to add items to the combo box
cboToolSizeFrom.AddItem rs.Fields("Dimensions") 'this adds items from field1 into the combo box
cboToolSizeTo.AddItem rs.Fields("Dimensions") 'this adds items from field1 into the combo box
rs.MoveNext 'moves next record
Loop
rs.MoveFirst
fillfieldDimensions 'i'll explain this later on.
Me.MousePointer = 0 'sets the mouse pointer to the normal arrow
rs.Close
End Sub