By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,594 Members | 2,059 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,594 IT Pros & Developers. It's quick & easy.

Add Items From A Database

P: 10
i have created a program that when a user types data , it will search for it, when the user searches for it, i want to make it so the user can add the item and remove the item if they wanted to.

my coding so far is

Private Sub cmdSearch_Click()
If opt1 Then
Data1.RecordSource = "SELECT * FROM [Table] WHERE [Reference]='" & CStr(txtSearch.Text) & "'"
Data1.Refresh
End If

If opt2 Then
Data1.RecordSource = "SELECT * FROM [Table] WHERE [Item]='" & CStr(txtSearch.Text) & "'"
Data1.Refresh
End If

If opt3 Then
Data1.RecordSource = "SELECT * FROM [Table] WHERE [Item Description]='" & CStr(txtSearch.Text) & "'"
Data1.Refresh
End If

If opt4 Then
Data1.RecordSource = "SELECT * FROM [Table] WHERE [Quantity]='" & CStr(txtSearch.Text) & "'"
Data1.Refresh
End If

If opt5 Then
Data1.RecordSource = "SELECT * FROM [Table] WHERE [Price]='" & CStr(txtSearch.Text) & "'"
Data1.Refresh
End If

txtSearch.Text = ""
DBGrid1.Visible = True
End Sub
Nov 22 '07 #1
Share this Question
Share on Google+
8 Replies


lotus18
100+
P: 866

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSearch_Click()
  2.  
  3. If opt1.Value = 1Then
  4.      Data1.RecordSource = "SELECT * FROM [Table] WHERE [Reference]='" &   CStr(txtSearch.Text) & "'"
  5.      Data1.Refresh
  6. ElseIf opt2.Value = 1 Then
  7.      Data1.RecordSource = "SELECT * FROM [Table] WHERE [Item]='" &  CStr(txtSearch.Text) & "'"
  8. Data1.Refresh
  9. ElseIf opt3.Value = 1 Then
  10. Data1.RecordSource = "SELECT * FROM [Table] WHERE [Item Description]='" & CStr(txtSearch.Text) & "'"
  11. Data1.Refresh
  12. ElseIf opt4.Value = 1 Then
  13.      Data1.RecordSource = "SELECT * FROM [Table] WHERE [Quantity]='" &    CStr(txtSearch.Text) & "'"
  14.      Data1.Refresh
  15. Else
  16.      Data1.RecordSource = "SELECT * FROM [Table] WHERE [Price]='" & CStr(txtSearch.Text) & "'"
  17.      Data1.Refresh
  18. End If
  19.  
  20. txtSearch.Text = ""
  21. DBGrid1.Visible = True
  22. End Sub
  23.  
Hi

Is this working?
Try the Insert and Delete
Nov 22 '07 #2

P: 10
yes the program does work.
Nov 22 '07 #3

lotus18
100+
P: 866
yes the program does work.
Here's an example for inserting and deleting a record

Expand|Select|Wrap|Line Numbers
  1.  
  2. "Insert Into <TableName> ([<FieldName>]) Values ('" & Text1.Text &  "')"
  3.  
  4. "Delete From <TableName> Where <FieldName>='" & Text1.Text & "'"
  5.  
  6.  
Note:

Omit < and >. For deleting an item, it is recommended to used the primary key in the given sample above
Nov 22 '07 #4

P: 10
so does that add/delete the row onto a new database?
Nov 23 '07 #5

lotus18
100+
P: 866
so does that add/delete the row onto a new database?
Hi Gemmalouise1988

Nope. This is not for creating a new database but this is for adding/deleting a record from your existing database. Or do I misinterpret your post?
Nov 23 '07 #6

P: 10
sorry i think i didnt explain it properly lol

i have one database listing all the items

and then another one so when the user decides to buy an item, it shows what she has bought, and i would like it so if the user decided they didnt want a certain item they could remove it.
Nov 23 '07 #7

lotus18
100+
P: 866
sorry i think i didnt explain it properly lol

i have one database listing all the items

and then another one so when the user decides to buy an item, it shows what she has bought, and i would like it so if the user decided they didnt want a certain item they could remove it.
I think you have to create a temporary list of items probably using a listvwiew or listbox, etc to let you view all the items you selected so that you can select the items you want to delete, then when it is final thats the time you save it to your database. btw, pinoy ka?
Nov 23 '07 #8

P: 10
ahhh right, i get it

THANK YOU!!!
Nov 23 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.