Access Database Management With Excel Userform

Access Database Example          

        We have two files in a folder named Personel.xls (Excel workbook) and Personel.mdb (Access database file).
The Access file contains PERSONEL table with personnel information.


       
         There is a userform in the Excel workbook with many VBA controls on it. Through userform, we will do operations onto the Access database ,such as adding data , deleting data, changing data  and querying the database.

With this userform ;

☑️ New data can be added to Access Database
☑️ Data can be changed
☑️ Data can be deleted
☑️ Data can be searched in Access Database
☑️ Data can be transferred from the Access Database to Excel.

We used the Adodb Connection Object for connection to Access database. Codes to connect :
Sub baglanti()
Set baglan = CreateObject("adodb.connection")
#If VBA7 And Win64 Then
baglan.Open "provider=microsoft.ace.oledb.12.0;data source=" & ThisWorkbook.Path & "\PERSONEL.mdb"
#Else
baglan.Open "provider=microsoft.jet.oledb.4.0;data source=" & ThisWorkbook.Path & "\PERSONEL.mdb"
#End If
End Sub


From access database to excel

         We will do all the operations related (data adding,deleting,changing etc.) to the database with the Adodb Connection Object that we created. 
Set baglan = CreateObject("adodb.connection")

For example , let's add a new record to Access database .
Private Sub CommandButton3_Click()
Dim i As Byte
On Error GoTo hata
For i = 0 To 51
If Mid(UserForm1.Controls(i).Name, 1, 3) = "txt" Then
If UserForm1.Controls(i).Value = "" Then
MsgBox "Required field is missing.", vbCritical + vbOKOnly
Exit Sub
End If
End If
If Mid(UserForm1.Controls(i).Name, 1, 3) = "cmb" Then
If UserForm1.Controls(i).Value = "" Then
MsgBox "Required field is missing.", vbCritical + vbOKOnly
Exit Sub
End If
End If
Next i

kod = "'" & txtCalisanKod & "'"
ad = "'" & txtAdi & "'"
dtarih = "'" & txtDtarih & "'"
soyad = "'" & txtSoyadi & "'"
tc = "'" & txtTC & "'"
sgk = "'" & txtSGK & "'"
dyeri = "'" & txtDyeri & "'"
baba = "'" & txtBabaAdi & "'"
anne = "'" & txtAnneAdi & "'"
gtarih = "'" & txtGirisTarih & "'"
ucret = "'" & txtUcret & "'"
vno = "'" & txtVergiNo & "'"
adres = "'" & txtAdres & "'"
Email = "'" & txtEmail & "'"
il = "'" & txtIl & "'"
ilce = "'" & txtIlce & "'"
semt = "'" & txtSemt & "'"
evtel = "'" & txtEvtel & "'"
ceptel = "'" & txtCeptel & "'"
cinsiyet = "'" & cmbCinsiyet & "'"
departman = "'" & cmbDepartman & "'"
gorev = "'" & cmbGorev & "'"
uturu = "'" & cmbUcretturu & "'"

Call baglanti
Set rs = baglan.Execute("INSERT INTO PERSONEL (CALISAN_KODU,ADI,SOYADI,TC_KIMLIK,DOGUM_TARIHI,CINSIYET,DOGUM_YERI,BABA_ADI,ANNE_ADI,GIRIS_TARIH,SGK,VERGI_NO,ADRES,DEPARTMAN,GOREVI,UCRET_TURU,UCRET,IL,ILCE,SEMT,EV_TEL,CEP_TEL,EMAIL) Values _
(" & kod & "," & ad & "," & soyad & "," & tc & "," & dtarih & "," & cinsiyet & "," & dyeri & "," & baba & "," & anne & "," & gtarih & "," & sgk & "," & vno & "," & adres & "," & departman & "," & gorev & "," & uturu & "," & ucret & "," & il & "," & ilce & "," & semt & "," & evtel & "," & ceptel & "," & Email & ")")
Set baglan = Nothing: Set rs = Nothing:

temizle
ListBox1.Clear
MsgBox "New record was added.", vbInformation + vbOKOnly
Label25.Caption = "Total Records = " & ListBox1.ListCount

hata:
If Err = -2147217913 Then
MsgBox "The salary must be numeric values and The dates must be valid date (e.g.: 20.12.2009)", vbCritical + vbOKOnly
End If
End Sub

18 comments:

  1. Hi
    I am not able to download the example file.Can you share a direct link for the same

    ReplyDelete
    Replies
    1. I am using link shortening service.If you have "Ad Block" application etc. in your browser,you must close it.

      Link :http://adf.ly/1ZHlla

      Delete
  2. Respected Sir,
    Excellent Programming. Can you provide templetes alongwith VBA code to my email (ylnvprasadrao5@gmail.com) or proved download link.

    ReplyDelete
  3. Ayrıca elinizde hazırda combobox ve listbox olan kaydet sil değiştir bul formatı bir çalışma olsada işimi görür.

    ReplyDelete
  4. merhabalar çalışma mükemmel olmuş. Elinize sağlık.
    tam istediğim bir çalışma sizden talebim ayrı veritabanı olmaması ve tüm çalışmanın excel içinde olması ayrıca bütün sutunlarda arama yapabilmem bu konuda yardımlarınızı bekliyorum teşekkür ederim.
    Ayrıca elinizde hazırda combobox ve listbox olan kaydet sil değiştir bul formatı bir çalışma olsada işimi görür.

    ReplyDelete
    Replies
    1. Access'in veri tabanı olarak Excel'den üstün yönleri var.O yüzden Access ile beraber kullandım.Sadece Excel ile yapılmış örnekler blog içinde var .

      Delete
  5. Kadir bey örneklere baktım tam isteğimi karşılayan çalışma bu, belirtmiş olduğum gibi düzeltme yapma fırsatınız var ise memnun kalırım. textbox listbox combobox arama kaydetme değiştir sil ve aktarma olan bir çalışmaya raslamadım. çalışmanız gerçekten çok emek verilerek hazırlanmış ve gerçekten çok hoş bu çalışmada birde verilerin gösterildiği combobox ve texboxlarda aratabilirseniz mükemmel olur diye düşünüyorum.(veri girilen kısımların içinde o alanla ilgili kısmı aratma combobox ve textbox bölümünden tüm verileri arama yapabilme.)

    ReplyDelete
  6. Merhabalar;
    Excel Dosyası Farklı bilgisayarlarda olacak ve data olarak PERSONEL.mdb yi şifreli olarak bu adresten çalıştırabilirmiyim.
    Dosyanın bulunduğu adres
    http://xxxxx.com/PERSONEL.mdb

    Yardımcı olursanınız memnun kalırım.

    ReplyDelete
    Replies
    1. Şifre derken dosyaya giriş şifresi mi?

      Delete
    2. PERSONEL.mdb yi hosta koyacağım ve PERSONEL.mdb şifreli olacak excel şifreli olarak data yazacak üzerine ilginiz için teşekkür ederim

      Delete
    3. Şifre olmasa da olabilir.
      PERSONEL.mdb hostta diğer excel farklı bilgisayarlarda olacak. Yardımcı olursanız sevinirim.

      Delete
  7. Dear MR Kadr
    Appreciate if you could do more project something like this which you use Ms Access as a database.

    ReplyDelete
  8. Bonjour Monsieur,
    Bonjour, j'aimerai bien profiter de cet userform, dans le cas ou la base de donnée est sur excel ?
    merci par avance

    ReplyDelete
  9. Don't click on download. Its click bait!!

    ReplyDelete
  10. Hi
    I am not able to download the example file.Can you share the file on my mail.
    rsg.0022@gmail.com

    ReplyDelete
  11. Sir, I have successfully downloaded your template. But unable to make any edit or add. It's saying "The salary must be numeric values and The dates must be valid date (e.g.: 20.12.2009)". Guide me how I have avoid the pop-up. Please inbox me at chauhan4175@gmail.com

    ReplyDelete
  12. Hello, Thank you for this file,
    but unable to make any edit or add. It's saying "The salary must be numeric values and The dates must be valid date (e.g.: 20.12.2009)". sandrymorg@gmail.com

    ReplyDelete