techwayservices
Oct 26th, 2005, 06:07 PM
Ok I have been programming in VB access for about 2 weeks and need help. I just found out how to query the database and load information into the combobox which is great but it still has bugs. When the user clicks on the equipment or the manufacture combobox I need it to requery(get rid of existing values which it is doing) and populate the model combobox(will not and giving me the error that it has no current recordset). My second issue is when I try to select the value it does not select. I created a counter ctr so it wont keep populating after multiple clicks. Here is my code thus far:
Dim ctr As Integer
Public Sub Event_Counter()
ctr = ctr + 1
End Sub
Private Sub btn_add_inv_entry_Click()
On Error GoTo Err_btn_add_inv_entry_Click
Dim stDocName As String
Exit_btn_add_inv_entry_Click:
Exit Sub
Err_btn_add_inv_entry_Click:
MsgBox Err.Description
Resume Exit_btn_add_inv_entry_Click
End Sub
Private Sub cbo_equip_type_Click()
cbo_Model_No.RowSource = vbNullString
cbo_Model_No.Requery
ctr = 0
End Sub
Private Sub cbo_MFG_Click()
ctr = 0
cbo_Model_No.RowSource = vbNullString
cbo_Model_No.Requery
ctr = 0
End Sub
Private Sub cbo_Model_No_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ADOCn As ADODB.Connection
Dim ConnString As String
Dim adoRS As ADODB.Recordset
Dim sSQL As String
Dim MFG As Variant
Dim EquipType As Variant
MFG = cbo_MFG.Value
EquipType = cbo_equip_type.Value
cbo_Model_No.RowSourceType = "Value List"
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=\\Fileserver\Data\Inventorydb\Techway.mdb;" & _
"Persist Security Info=False"
Set ADOCn = New ADODB.Connection
ADOCn.ConnectionString = ConnString
ADOCn.Open ConnString
Set adoRS = New ADODB.Recordset
sSQL = "Select ID, Model_No From dbo_MFG_Model_No Where MFG_Name Like '" & MFG & "' And Equip_Type Like '" & EquipType & "'"
adoRS.Open sSQL, ADOCn
If ctr = 0 Then
Do Until adoRS.EOF
'It is Crapping out saying no recordset and requery I suspect is the culprit
cbo_Model_No.AddItem adoRS.Fields.Item("Model_No").Value
adoRS.MoveNext
Loop
End If
adoRS.Close
ADOCn.Close
Set ADOCn = Nothing
Set adoRS = Nothing
Event_Counter
End Sub
Dim ctr As Integer
Public Sub Event_Counter()
ctr = ctr + 1
End Sub
Private Sub btn_add_inv_entry_Click()
On Error GoTo Err_btn_add_inv_entry_Click
Dim stDocName As String
Exit_btn_add_inv_entry_Click:
Exit Sub
Err_btn_add_inv_entry_Click:
MsgBox Err.Description
Resume Exit_btn_add_inv_entry_Click
End Sub
Private Sub cbo_equip_type_Click()
cbo_Model_No.RowSource = vbNullString
cbo_Model_No.Requery
ctr = 0
End Sub
Private Sub cbo_MFG_Click()
ctr = 0
cbo_Model_No.RowSource = vbNullString
cbo_Model_No.Requery
ctr = 0
End Sub
Private Sub cbo_Model_No_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ADOCn As ADODB.Connection
Dim ConnString As String
Dim adoRS As ADODB.Recordset
Dim sSQL As String
Dim MFG As Variant
Dim EquipType As Variant
MFG = cbo_MFG.Value
EquipType = cbo_equip_type.Value
cbo_Model_No.RowSourceType = "Value List"
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=\\Fileserver\Data\Inventorydb\Techway.mdb;" & _
"Persist Security Info=False"
Set ADOCn = New ADODB.Connection
ADOCn.ConnectionString = ConnString
ADOCn.Open ConnString
Set adoRS = New ADODB.Recordset
sSQL = "Select ID, Model_No From dbo_MFG_Model_No Where MFG_Name Like '" & MFG & "' And Equip_Type Like '" & EquipType & "'"
adoRS.Open sSQL, ADOCn
If ctr = 0 Then
Do Until adoRS.EOF
'It is Crapping out saying no recordset and requery I suspect is the culprit
cbo_Model_No.AddItem adoRS.Fields.Item("Model_No").Value
adoRS.MoveNext
Loop
End If
adoRS.Close
ADOCn.Close
Set ADOCn = Nothing
Set adoRS = Nothing
Event_Counter
End Sub