Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

Thread Tools Rate Thread Display Modes
Old 07-17-2010, 11:37 AM   #1
Registered User
Join Date: Jul 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
sunny1 is on a distinguished road
Vba code for add,delete and update a record in access table through command button?

Hi all...
I have written a code to search a record from a table but I am not able to add ,delete and update operation.please give some idea or code to perform these task.I am just a beginner.so, I dont have much idea how to work in vba... below I am posting my code for search,add,and delete where search is only working fine...please correct this code.
Private Sub cmdSearch_Click()

Dim rs As DAO.Recordset, db As DAO.Database
Dim res As Boolean

'Set db = CurrentDb.Connect

OpenDatabase ("C:\1.mdb")

If Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
MsgBox "You must enter a search string."

Set rs = CurrentDb.OpenRecordset("select * from user where user_Id='" & txtSearchString & "'")
If Not rs Then
Do Until rs.EOF
' MsgBox rs.Fields("user_Id")
' MsgBox rs.Fields("last_name")
' MsgBox rs.Fields("first_name")
' MsgBox rs.Fields("email_id")
' MsgBox rs.Fields("password")
' MsgBox rs.Fields("user_type")
' MsgBox rs.Fields("status")

User_Id.Value = rs.Fields("user_Id")
Last_Name.Value = rs.Fields("last_name")
First_Name.Value = rs.Fields("first_name")
Email_Id.Value = rs.Fields("email_id")
Password.Value = rs.Fields("password")
User_Type.Value = rs.Fields("user_type")
Status.Value = rs.Fields("status")

res = True
End If

End If

If (res = True) Then
MsgBox "User id found"
MsgBox "User id not found"
End If


End Sub

Private Sub cmdAdd_Click()
On Error GoTo Err_cmdAdd_Click

DoCmd.GoToRecord , , acNewRec

Exit Sub

MsgBox Err.Description
Resume Exit_cmdAdd_Click

End Sub
Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit Sub

MsgBox Err.Description
Resume Exit_cmdDelete_Click

End Sub
Attached Files
File Type: zip admin.zip (9.1 KB, 585 views)

sunny1 is offline   Reply With Quote
Old 07-28-2010, 05:26 AM   #2
Trevor G
Newly Registered User
Trevor G's Avatar
Join Date: Oct 2009
Location: Tamworth, Staffordshire
Posts: 2,331
Thanks: 4
Thanked 229 Times in 219 Posts
Trevor G will become famous soon enough Trevor G will become famous soon enough
Re: Vba code for add,delete and update a record in access table through command butto

In your form you will have a command button wizard which will allow you to select to Add and also Delete and a few other features which will work on your form.

You need to ensure the wizard is switched on.
I am on a learning curve of life, I know a little but like to share what I have learnt with others.
I am using Microsoft Office 2003 To 2016
Please remember everyone here is a volunteer, so if you have had a reply to your thread be courteous and acknowledge this.
Trevor G is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help in automatic updating database from xml pushkar1986 Modules & VBA 6 05-27-2013 12:13 PM
VBA Code to update a record - not working PNGBill Modules & VBA 7 07-12-2010 10:13 PM
Access - how to programatically unlock vba code dreamdelerium Modules & VBA 1 02-19-2009 11:58 PM
Need VBA code for Update Table Record, Need help? furnitureheaven Modules & VBA 3 01-09-2009 06:22 AM
Update entire record using VBA Timtropolis Modules & VBA 1 05-11-2006 11:44 AM

All times are GMT -8. The time now is 05:23 PM.

Microsoft Access Help
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post

Sponsored Links

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World