Hi guys,
I have a program here using access as database. What in trying to figure out is how i can use the correct database/table as per textbox indicated. I have frmmain, frmproductsearch, a textbox (txtdepotcode) and database (database) with table (product, product1, product2, product3, product4, product5 and product6) command button(cmdsearchproduct). Lets say I typed 0 at the textbox (txtdepotcode) when i click command button(cmdsearchproduct), frmproductsearch will show up using product as its table and so on and so fort. Im thinking of using Select Case Statement. Below are some of the codes ive tried:
Looking forward for your help,
Chino:)
I have a program here using access as database. What in trying to figure out is how i can use the correct database/table as per textbox indicated. I have frmmain, frmproductsearch, a textbox (txtdepotcode) and database (database) with table (product, product1, product2, product3, product4, product5 and product6) command button(cmdsearchproduct). Lets say I typed 0 at the textbox (txtdepotcode) when i click command button(cmdsearchproduct), frmproductsearch will show up using product as its table and so on and so fort. Im thinking of using Select Case Statement. Below are some of the codes ive tried:
Code:
Private Sub cmdsearchproduct_Click()
frmproductsearch.Show
End Sub
Code:
::::frmproductsearch::::
Option Explicit
Dim lst As ListItem
Dim lst1 As ListItem
Dim productcode As Long
Dim warning As String
Dim countertitle As Integer
Public Sub FillListView()
Set lst = lvproduct.ListItems.Add(, , txtcode.Text)
With lst
.SubItems(1) = rs!code
.SubItems(2) = rs!erb
.SubItems(3) = rs!Description
.SubItems(4) = rs!enterby
.SubItems(5) = rs!casesize
.SubItems(6) = rs!unitsize
.SubItems(7) = rs!category
.SubItems(8) = rs!subcategory
End With
End Sub
Private Sub cmdproductsearchclose_Click()
Unload Me
End Sub
Private Sub cmdrefresh_Click()
lvproduct.ListItems.Clear
Call GetProductRecord
End Sub
Private Sub Form_Load()
txtcode.Text = 1
Call GetProductRecord
Connection
sql = "SELECT code FROM product"
Set rs = New ADODB.Recordset
rs.Open sql, Conn, adOpenDynamic, adLockOptimistic
If Not rs.EOF Then
With rs
.MoveLast
txtcode.Text = !code + Val(1)
.Close
End With
End If
End Sub
Public Sub GetProductRecord()
Connection
sql = "product"
Set rs = New ADODB.Recordset
rs.Open sql, Conn, adOpenDynamic, adLockOptimistic
Do Until rs.EOF
Set lst1 = lvproduct.ListItems.Add(, , rs!code)
With lst1
.SubItems(1) = rs!erb
.SubItems(2) = rs!Description
.SubItems(3) = rs!enterby
.SubItems(4) = rs!casesize
.SubItems(5) = rs!unitsize
.SubItems(6) = rs!category
.SubItems(7) = rs!subcategory
End With
rs.MoveNext
Loop
rs.Close: Set rs = Nothing
End Sub
Private Sub lvproduct_Click()
End Sub
Private Sub txtproductcategory_Change()
lvproduct.ListItems.Clear
Connection
'Call connect
sql = "SELECT * FROM product WHERE category LIKE '" & Trim(txtproductcategory.Text) & "%'"
Set rs = New ADODB.Recordset
rs.Open sql, Conn, adOpenDynamic, adLockOptimistic
If Not rs.EOF Then
Do Until rs.EOF
Set lst1 = lvproduct.ListItems.Add(, , rs!code)
With lst1
.SubItems(1) = rs!erb
.SubItems(2) = rs!Description
.SubItems(3) = rs!enterby
.SubItems(4) = rs!casesize
.SubItems(5) = rs!unitsize
.SubItems(6) = rs!category
.SubItems(7) = rs!subcategory
End With
rs.MoveNext
Loop
End If
rs.Close: Set rs = Nothing
End Sub
Private Sub txtproductcode_Change()
lvproduct.ListItems.Clear
Connection
sql = "SELECT * FROM Product WHERE UCase(code) LIKE '%" & UCase(txtproductcode.Text) & "%'"
Set rs = New ADODB.Recordset
rs.Open sql, Conn, adOpenDynamic, adLockOptimistic
If Not rs.EOF Then
Do Until rs.EOF
Set lst1 = lvproduct.ListItems.Add(, , rs!code)
With lst1
.SubItems(1) = rs!erb
.SubItems(2) = rs!Description
.SubItems(3) = rs!enterby
.SubItems(4) = rs!casesize
.SubItems(5) = rs!unitsize
.SubItems(6) = rs!category
.SubItems(7) = rs!subcategory
End With
rs.MoveNext
Loop
End If
rs.Close: Set rs = Nothing
End Sub
Private Sub txtproductdescription_Change()
lvproduct.ListItems.Clear
Connection
sql = "SELECT * FROM Product WHERE UCase(Description) LIKE '%" & UCase(txtproductdescription.Text) & "%'"
Set rs = New ADODB.Recordset
rs.Open sql, Conn, adOpenDynamic, adLockOptimistic
If Not rs.EOF Then
Do Until rs.EOF
Set lst1 = lvproduct.ListItems.Add(, , rs!code)
With lst1
.SubItems(1) = rs!erb
.SubItems(2) = rs!Description
.SubItems(3) = rs!enterby
.SubItems(4) = rs!casesize
.SubItems(5) = rs!unitsize
.SubItems(6) = rs!category
.SubItems(7) = rs!subcategory
End With
rs.MoveNext
Loop
End If
rs.Close: Set rs = Nothing
End Sub
Looking forward for your help,
Chino:)