Loading

A Simple Add, Edit, Delete, and Search using VB and MSAccess

Submitted by: 
Visitors have accessed this post 187475 times.


This is a sample program on how to Add, Edit, Delete, and Search entries in database using VB and MS Access. Hope my code help you.
NOTE: THIS PROGRAM USES OCX, YOU MUST INSTALL THE PROJECT COMPONENTS BEFORE RUNNING THE PROGRAM.




Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Private Sub cmdSearch_Click()
If Me.cmbSearch.Text = "" Or Me.txtSearch.Text = "" Then
MsgBox "All fields are required!", vbExclamation, "Error"
Exit Sub
End If

Select Case LCase(Me.cmbSearch.Text)
Case "Last Name"
SQL = "SELECT tbl_info.lastname, tbl_info.id_info, tbl_info.lastname, tbl_info.firstname, tbl_info.area, tbl_info.department, tbl_info.badge, tbl_info.cid, tbl_info.date_hire, tbl_info.date_resigned " & _
"From tbl_info WHERE (((tbl_info.lastname) Like '" & Me.txtSearch.Text & "%')) order by tbl_info.lastname asc;"
Unload Me
Call goSearch(SQL)

Case "Badge No"
SQL = "SELECT tbl_info.badge, tbl_info.id_info, tbl_info.lastname, tbl_info.firstname, tbl_info.area, tbl_info.department, tbl_info.badge, tbl_info.cid, tbl_info.date_hire, tbl_info.date_resigned " & _
"From tbl_info WHERE (((tbl_info.badge) Like '" & Me.txtSearch.Text & "%')) order by tbl_info.lastname asc;"
Unload Me
Call goSearch(SQL)
End Select

End Sub

are this columns not in the same table?

else we can:

  1. Public element As ListItem
  2. Public con As New ADODB.Connection
  3. Public rs As New ADODB.Recordset
  4.  
  5. Public Sub Connect()
  6. If con.State = adStateOpen Then con.Close
  7. con.Provider = "Microsoft.JET.OLEDB.4.0"
  8. con.Open App.Path & "\DB.mdb"
  9. End Sub
  10.  
  11. Public Sub OpenRecord(ByVal sql As String)
  12. Connect
  13. If rs.State = adStateOpen Then rs.Close
  14. rs.Open sql, con, 1, 2
  15. End Sub
  16.  
  17.  
  18. Private Sub cmbSearch_Change()
  19.  
  20. OpenRecord "Select * from TBL_INFO where TBL_INFO.BADGE LIKE '" & CMBSEARCH.TEXT & "%'"
  21.  
  22. mainFORM.LISTVIEW.ListItems.Clear
  23.  
  24. While Not rs.EOF
  25.  
  26. Set element = mainFRM.SLV.ListItems.Add(, , rs.Fields(0).Value)
  27. element.SubItems(1) = rs.Fields(1).Value
  28. element.SubItems(2) = rs.Fields(2).Value
  29. element.SubItems(3) = rs.Fields(3).Value
  30. element.SubItems(4) = rs.Fields(4).Value
  31. element.SubItems(5) = rs.Fields(5).Value
  32. (and so on how many columns you have to display)
  33. rs.MoveNext
  34.  
  35. Wend
  36. End Sub

DATA WILL DISPLAY TO YOUR LISTVIEW AS SOON AS YOU ARE TYPING LETTERS TO YOUR TEXTBOX OR CHANGING STRINGS ON YOUR COMBO BOX.

Project po kc nmin sa subject na Software Engineering na gumawa ng System Software...if there's anyone here kind enough to teach me and help me to do my project please with all my gratitude im begging you to teach me...pls pls pls...any idea is accepted as long as maintindihan ko po...im just a beginner po kc...thanks so much.

please email me at...mhike_strong@yahoo.com
waiting for positive response...

sakura's picture

..sir pwede mg.ask about sa codes for null values....f u have time email to bbder_08@yahoo.com...

sir i have written a command in sql that is create database college.,but there was a error message that master cant create database ,access denied ,,,,,,,tell me step by step solution for this problem.

Set Item = .Add(, , RS!trans)
Item.SubItems(1) = RS!E
Item.SubItems(2) = RS!T
Item.SubItems(3) = RS!em
Item.SubItems(4) = RS!tm

Run-time error '3265':

item cannot be found in the collection corresponding to the requested name or ordinal.

please send any solution to my email sit_me@yahoo.com.ph

in the vb project Add, Edit, Delete, Search i want add a few more tabs that is columns like email id , dob etc can u pls give me the steps to do tat

hai can u give me a code that have insert,deleteand search plzzzz....

plz help me for the code that can edit,save,preview cancel,search,and delete
using vb msaccess...plz poh

private sub cmdsave_click()

with adodc1.recordset
.addnew
.fields(0) = txtId_number.text
.fields(1) = txtFirstname.text
.fields(2) = txtMiddlename.text
.fields(3) = txtLastname.text
.update
end with
end sub

private sub cmddelete_click()
on error resume next
dim confirm as string
confirm = msgbox("sigurado ka na gusto mong burahin itong record?",vbExclamation+vbYesOrNo,"Confirm"
if confirm = vbYes then
adodc1.recordset.delete
msgbox"Itong Record ay burado na",vbOkOnly,"Burado"
else
msgbox"Nakansela ang pagbubura",vbOkOnly,"Kansela"
end if
end sub

yan po sana Kahit pano mkatulong po Godbless......

Where is the code for Search my dear....

hi i found ur program very useful
however can u help me coz im using Mysql5.0 as database
and i want to know how deleting of records goes
and also the sorting (Highest - Lowest)
im using VB 2008 and Mysql any help will be much appreciated!
Godbless!

hi i found ur program very useful
however can u help me coz im using Mysql5.0 as database
and i want to know how deleting of records goes
and also the sorting (Highest - Lowest)
im using VB 2008 and Mysql any help will be much appreciated!
Godbless!

can you help me doing my project. please...

hello
can u tell me how can i use a progressbar to count the records in the databae ?
tnk u

hi!.. can you give me the code of add, edit, delete and search.. thank you..!

can you give me the simple code for add,edit,delete,print,clear using the vb.net?connected to the sql.....

plz giv VB code - record set Add, New, Edit, Delete, previous, next last, and first

Sir,

can you give me the simple code for add,edit,delete,print,previous, next, using the VB.connected to the MS access and excel.

ichus

Public dbCN As ADODB.Connection
Public Uname As String
'Connect to database
Public Function DBConnect() As Boolean

On Error GoTo OpenErr

Dim MSDatabase

Set dbCN = New ADODB.Connection
MSDatabase = App.Path & "\" & "library1.mdb"

dbCN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MSDatabase & ";Persist Security Info=False;Jet OLEDB:Database Password = "
DBConnect = True
Exit Function

OpenErr:

MsgBox "Error Opening " & MSDatabase & vbNewLine & Err.Description, vbCritical, "Open Database Error"
DBConnect = False

End Function

Hi! can you help me how to delete, add, search, and edit records from access database using text boxes, datagridview in vb 2010.., thanks poh! Godbless!!!

pleaswe?

Public dbCN As ADODB.Connection
Public Uname As String
'Connect to database
Public Function DBConnect() As Boolean

On Error GoTo OpenErr

Dim MSDatabase

Set dbCN = New ADODB.Connection
MSDatabase = App.Path & "\" & "library1.mdb"

dbCN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MSDatabase & ";Persist Security Info=False;Jet OLEDB:Database Password = "
DBConnect = True
Exit Function

OpenErr:

MsgBox "Error Opening " & MSDatabase & vbNewLine & Err.Description, vbCritical, "Open Database Error"
DBConnect = False

End Function

Sir,
Please send how to insert time format in a textbox(00:00:00 AM/PM) with time calculations.And the codes for edit, delete in vb.net connecting sql server? kavi.it10@gmail.com

how to search a particular record in vb6 by using data control pls tell me code
by sridhar

i just want to ask, what is the code for deleting the files?
toolstrip gmit ku. then i want to delete the files na nandun. i used database with MS Access 2007.then visual basic 2008 gmit ku. ge thank you.

hlow sir how to connect vb6 to msAccess using adodc.tnx sir plz hlp me

wats wrong po wid these codes...search button po
Private Sub cmdfind_Click()

Dim Find As String
Dim sBookmark As String

Find = InputBox("Please Enter ID number:", "ID number")
Find = Trim$(search) 'remove surplus spaces

If Find "" Then 'cancel if nothing entered

With Datenrolment.Recordset
sBookmark = .Bookmark
.FindFirst "id like'" + Find + "*'"

If .NoMatch Then 'record not found
MsgBox "Sorry, No record found.", vbCritical, "Error"
.Bookmark = sBookmark
End If

End With
End If

Datenrolment.Recordset.OpenRecordset
cmdedit.Enabled = True
cmdexit.Enabled = True

End Sub

.FindFirst "id like'" & Find & "%'"

can i apply this on vb 2010, thanks!

ANU PO BA AND CODE NG ADD,DELETE AT EXIT PG GNAMIT MO PO SA FOXPRO..
EMAIL NIO PO SA dumalaguej@yahoo.com

salamt po....

email mo ko. jgerald_molina@yahoo.com turuan kita ^^

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Private Sub cmdAdd_Click()
cmdAdd.Enabled = False
cmdSave.Enabled = True
rs.AddNew
ClearFields
End Sub
Public Sub ClearFields()
Text10.Text = ""
Text9.Text = ""
Text8.Text = ""
Text7.Text = ""
Text6.Text = ""
cboGender.Text = "choose"

End Sub

sir! how to connect visual basic 6.0 to MSAccess with add, delete, edit, preview,

can u give me the code of edit and how to maintenance in ms access
tank u sir...e2 email q germangolbeque20@yahoo.com

i need a complete code for search engine for my enrollment system using visualbasic2008 express edition...tnx poh...kindly email it to dounigwapo@ymail.com
tnx a lot and God speed

Dear sir/madam:

I had use a "cdobox1" in my form, to do a getitem in my field for table "Remark".

I want the content in the "Remark" from the table to display in my "txtbox1" in my form.

what can i do?

BEST FOR EVERY STUDENT.

can u plz help me to find a code for searching...

Private Sub cmdAdd_Click()

With Adodc1.Recordset
.AddNew
.Fields(FName) = txtFirstName.Text
.Fields(LName) = txtLastName.Text
.Fields(MI) = txtMI.Text
.Fields(Add) = txtADD.Text
.Fields(Phone) = txtPNum.Text
.Fields(Mobile) = txtMNum.Text
.Fields(Nationality) = txtNat.Text
.Fields(Email) = txtEAdd.Text
.Fields(Status) = CboStat.Text
.Fields(Gender) = CboGen.Text
.Fields(Age) = txtA.Text
.Update
End With

End Sub

the word inside the open/close parenthesis is my field name.......

run-time error '3265':
Item cannot be found in the collection corresponding to the requested name or ordinal.
but still it saves my data but also it replaces the 1st data i already saved....

pls help me, this error is causing me headache....
here's my email, gs.gladys_sacueza@yahoo.com
hope someone can reply.... thank so much

sir. . .can you help me. . .what codes in edit,delete,save, in vb2008 express edition. . .sir. . .no data base sir. . .pls.. .in vb2008 only. . .no have backend. . .tnx. . .u can send me sir in my. ..email or rply pls. . .tnx ulit. . .

same problem pls email the correct code tnx... paoluck19@yahoo.com

You did not enclose youre fieldnames with doublequotes like this .Fields("FName"); See if it works!

Private Sub cmdAdd_Click()

With Adodc1.Recordset
.AddNew
.Fields("FName") = trim(txtFirstName.Text)
.Fields("LName") = trim(txtLastName.Text)
.Fields("MI") = trim(txtMI.Text)
.Fields("Add") =trim( txtADD.Text)
.Fields("Phone") = trim(txtPNum.Text)
.Fields("Mobile") =trim( txtMNum.Text)
.Fields("Nationality") = trim(txtNat.Text)
.Fields("Email") = trim(txtEAdd.Text)
.Fields("Status") = trim(CboStat.Text)
.Fields("Gender") =trim( CboGen.Text)
.Fields("Age") =trim( txtA.Text)
.Save
adodc1.refresh
End With

End Sub

paano mag gawa ng code sa vb .net 2008 ex. add , save

please help i want a code of add,update,delete in asp.net

Good day! I am your one of the followers here. sir can you help me out, in your given example downloadable code in simple add, edit, delete and search.. i added one column in your database to get the output in currency. dko mapalabas sa list view yong amount. ng idinagdag ko na column sa access database. pakitulungan mo naman ako please..... send mo sa email ko ang codes. its mikki_gwapito@yahoo.com. salamat po.

Erman Murilla

Sir good day may project po akong CASH BOND PROGRAM in which kung saan lalabas lahat ng total cashbond ng empleyado kung magkanoi na binabayad sa loob ng pinasok nyang araw. inipattern ko sa downloadable add edit delete at search mo. pd bang gawan mo ko ng sample na code saung simple program. nag dagdag me ng isang column sa database access named cashbong kung san lalabas ang 50.00 na ouput napalabas ko sa database pero ayaw lumabas sa listview ng form 1 mo na example. ano kaya problems. tulungan mo naman me send mo sa email ko.. gawin mo na pati yng program at usap nalang tau how much... mikki_gwapito@yahoo.com.

tnx....
Erman Murilla

Sir,
I'm doing my project using vb6 (using data form wizard to connect to database) and ms access as my database. Sir pls help me code for search, here is my email address yarisson4life@yahoo.com.
Thank sir

is it working in VB.NET ??

Pages

Add new comment

Filtered HTML

  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.