This is a continuation from a question I asked yesterday. The initial problem has been fixed, but now I am encountering an alltogether different problem. The structure of the code below works well in other subs, but this one in particular does not return any values from the database (Even though I know they exist). Your help is greatly appreciated.
Code:Sub CheckForSufficientInventory(ByRef proceed As Boolean, ByRef bomList As ArrayList, _ ByRef qtyList As ArrayList) ' CHECK STRINGCOLLECTION ARRAY AGAINST INVENTORY ' PROCEED IF SUFFICIENT INVENTORY OR ' NOTIFY USER OF DEFICIENCIES ' GIVE OPTION TO OVERRIDE Dim buildQty As Integer Dim canBuild As Integer Dim currentItem As String Dim currentQty As Integer Dim invQty As Integer Dim itemNumber As Integer Dim itemsShort As Integer Dim totalCanBuild As Integer = buildQty Dim selectString As String Try ' CREATE CONNECTION AND OPEN Dim invConString As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data " & _ "Source=******.mdb;" & _ "Jet OLEDB:Database Password=******;" invCon = New OleDbConnection(invConString) invCon.Open() ' CHECK INVENTORY For itemNumber = 1 To bomList.Count ' SET CURRENT ITEM AND QTY currentItem = bomList.Item(itemNumber - 1).ToString currentQty = Integer.Parse(qtyList.Item(itemNumber - 1).ToString) ' CREATE COMMAND AND SET PARAMETERS invCmd = New OleDbCommand invCmd.CommandType = CommandType.Text invCmd.CommandText = "SELECT invMain.PartNumber, invMain.Description1, " & _ "invMain.Description2, invMain.Type, invMain.Inventory" & _ " FROM invMain" & " WHERE (invMain.PartNumber=@comp)" invCmd.Parameters.Add("@comp", OleDb.OleDbType.Char) invCmd.Parameters("@comp").Value = currentItem invCmd.Connection = invCon ' EXECUTE COMMAND invRdr = invCmd.ExecuteReader ' IF DATA, READ INVENTORY If invRdr.HasRows Then invQty = Integer.Parse(invRdr(4).ToString) Else MessageBox.Show("No Rows") End If MessageBox.Show(currentItem & " " & Convert.ToString(invQty)) ' COMPARE QUANTITIES If invQty < currentQty * buildQty Then itemsShort = itemsShort + 1 canBuild = invQty \ currentQty If canBuild < totalCanBuild Then totalCanBuild = canBuild End If End If ' CLOSE READER FOR NEXT ITEM invRdr.Close() Next itemNumber ' IF INVENTORY IS SHORT, NOTIFY USER, RETURN PROCEED = FALSE If itemsShort > 0 Then MessageBox.Show("Insufficient inventory exists for " & itemsShort & " item(s)" & _ "at the selected quantity. " & vbCrLf & "You can build " & totalCanBuild & _ " units with current inventory levels.") proceed = False Else ' INVENTORY IS SUFFICIENT, RETURN PROCEED = TRUE proceed = True End If ' CLOSE CONNECTION invCon.Close() Catch ex As Exception MessageBox.Show(ex.Message) proceed = False End Try End Sub




Reply With Quote