Programming for Everybody: data entry access vba vba
Showing posts with label data entry access vba vba. Show all posts
Showing posts with label data entry access vba vba. Show all posts

Access database VBA programmer: Create insert update delete and search in another database with code



 Private Sub Command12_Click()

If (Not IsNull(Me.idtxt.Value)) Then

Dim dbs As DAO.Database

Set dbs = OpenDatabase("H:\rr.accdb")

Dim strsql As String

strsql = "Select firstname,lastname,marks,image1 From Table6 " _

& " Where id= " & Me.idtxt.Value & ""

Dim rst As DAO.Recordset

Set rst = dbs.OpenRecordset(strsql)

If rst.EOF Then

Me.Image1.Picture = ""

Me.ftxt.Value = ""

Me.ltxt.Value = ""

Me.mtxt.Value = ""

Else

Me.Image1.Picture = rst.Fields("image1")

Me.ftxt.Value = rst.Fields("firstname")

Me.ltxt.Value = rst.Fields("lastname")

Me.mtxt.Value = rst.Fields("marks")

End If

rst.Close

Else

MsgBox "Please Enter ID"

End If

End Sub


Private Sub Command13_Click()

Dim dbs As DAO.Database

Set dbs = OpenDatabase("H:\rr.accdb")

Dim strsql As String

strsql = "Update Table6 Set firstname='" & Me.ftxt.Value & "', " _

& "lastname = '" & Me.ltxt.Value & "',marks=" & Me.mtxt.Value & "," _

& "image1='" & Me.Image1.Picture & "' Where id= " & Me.idtxt.Value & ""

dbs.Execute (strsql)

MsgBox "Data Updated Successfully"

End Sub


Private Sub Command14_Click()

Dim dbs As DAO.Database

Set dbs = OpenDatabase("H:\rr.accdb")

Dim strsql As String

strsql = "Delete From Table6 Where id= " & Me.idtxt.Value & ""

dbs.Execute (strsql)

Me.Image1.Picture = ""

Me.ftxt.Value = ""

Me.ltxt.Value = ""

Me.mtxt.Value = ""

Me.idtxt.Value = ""

MsgBox "Data Deleted Successfully"

End Sub


Private Sub Command7_Click()

Dim img_of As Office.FileDialog

Dim img_var As Variant

Set img_of = Application.FileDialog(msoFileDialogFilePicker)

img_of.Title = "Please Select image"

img_of.Filters.Clear

img_of.Filters.Add "Images", "*.png; *.jpg"

If img_of.Show = True Then

For Each img_var In img_of.SelectedItems

Me.Image1.Picture = img_var

Next

Else

Me.Image1.Picture = ""

MsgBox "Please Select Image"

End If

End Sub


Private Sub Command8_Click()

Me.Image1.Picture = ""

Me.ftxt.Value = ""

Me.ltxt.Value = ""

Me.mtxt.Value = ""

Me.idtxt.Value = ""

End Sub


Private Sub Command9_Click()

Dim dbs As DAO.Database

Set dbs = OpenDatabase("H:\rr.accdb")

Dim strsql As String

strsql = "Insert Into Table6(firstname,lastname,marks,image1) " _

& " Values('" & Me.ftxt.Value & "','" & Me.ltxt.Value & "'," _

& "" & Me.mtxt.Value & ",'" & Me.Image1.Picture & "')"

dbs.Execute (strsql)

MsgBox "Data Inserted Successfully"

End Sub