Sub ImportObjectenBestand() ''Importeren van klantenbestand vanuit Acces
''ClearsheetImportklant ''"ImportKlnt"
txtzoek = ""
On Error GoTo Errhandler:
Application.ScreenUpdating = False
dbpath = DataSheet.Cells(7, 8).Value
''dbpath = "Z:\VanEijk\Offertes\VanEijk.accdb"
var = ""
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbpath
Sql = "SELECT * FROM ProjectenDb WHERE Id LIKE '" & var & "%" & "'"
Set rs = New ADODB.Recordset
rs.Open Sql, cnn
If rs.EOF And rs.BOF Then
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
Application.ScreenUpdating = True
''MsgBox "Kan de klantendatabase niet vinden.", vbCritical, "Geen database gevonden"
Exit Sub
End If
Sheet8.Range("A3").CopyFromRecordset rs
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
On Error GoTo 0
Exit Sub
Errhandler:
Set rs = Nothing
Set cnn = Nothing
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Importeren van personeelsdata"
End Sub
Private Sub CommandButton2_Click() ''Openen van offerte
If Me.ComboBox1.Value = "" Then
MsgBox "Offerte kiezen a.u.b.", vbInformation, "Geen offerte geselecteerd"
Me.ComboBox1.SetFocus
Exit Sub
End If
c00 = "Z:\VanEijk\Offertes\Excel\" & Left(ComboBox1.Value, 4) & "\" & ComboBox1.Value
c01 = Left(ComboBox1.Value, 4)
MsgBox c00
End Sub
Private Sub CommandButton5_Click() ''Toevoegen aan database
On Error GoTo Errhandler_Van_Eijk_DB:
dbpath = DataSheet.Cells(7, 8).Value ''"VanEijk.accdb"
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbpath
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM Numbers " & _
"WHERE Art LIKE '" & "Projecten" & "'", ActiveConnection:=cnn, _
CursorType:=adOpenDynamic, LockType:=adLockOptimistic, _
Options:=adCmdText
If rs.EOF And rs.BOF Then
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
MsgBox "Kan het nieuwe objectnummer niet wegschrijven naar database van de objecten.", vbCritical, "Fout met wegschrijven naar database"
Exit Sub
End If
Me.TextBox00.Caption = rs.Fields("Tot_Id").Value + 1
''''Sheet4.Cells(1, 2).Value = rs.Fields("Tot_Id").Value + 1
With rs
rs.Fields("Tot_Id").Value = rs.Fields("Tot_Id").Value + 1 ''rs = id_tot
rs.Fields("Lst_mut_by").Value = DataSheet.Cells(2, 3).Value ''Lst_mut_by
rs.Fields("lst_mut").Value = Format(Date, "d-m-yyyy") ''lst_mut
rs.Update
End With
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbpath
Set rs = New ADODB.Recordset
dbpath = DataSheet.Cells(7, 8).Value ''"VanEijkPersoneel.accdb"
dbTabl = "ProjectenDb"
rs.Open Source:=dbTabl, ActiveConnection:=cnn, _
CursorType:=adOpenDynamic, LockType:=adLockOptimistic, _
Options:=adCmdTable
On Error Resume Next
With rs
.AddNew
.Fields("Id").Value = Me.TextBox00.Caption
.Fields("Zoeknaam").Value = Me.TextBox0.Value
.Fields("Objectnaam").Value = Me.TextBox1.Value
.Fields("Objectadres").Value = Me.TextBox2.Value
.Fields("ObjectPostcode").Value = Me.TextBox3.Value
.Fields("ObjectPlaats").Value = Me.TextBox4.Value
.Fields("Cont_Object").Value = Me.TextBox5.Value
.Fields("Tel_Cont_Object").Value = Me.TextBox6.Value
.Fields("Mob__Cont_Object").Value = Me.TextBox7.Value
.Fields("Email__Cont_Object").Value = Me.TextBox8.Value
.Fields("Fact_naam").Value = Me.TextBox9.Value
.Fields("Fact_TAV").Value = Me.TextBox10.Value
.Fields("Fact_adres").Value = Me.TextBox11.Value
.Fields("Fact_Postcode").Value = Me.TextBox12.Value
.Fields("Fact_Postplaats").Value = Me.TextBox13.Value
.Fields("Fact_Email").Value = Me.TextBox14.Value
.Fields("Location").Value = Me.Txtbox17.Value
.Fields("HistoryOff").Value = Replace(Me.TextBox15.Value, vbCrLf, " | ")
.Fields("HistoryWerk").Value = Me.Txtbox16.Value
''.Fields("Id_omschr").Value = Me.Txtbox19.Value
''.Fields("extra").Value = Me.Txtbox90.Value
.Fields("lst_myt_by").Value = DataSheet.Cells(2, 3).Value
.Fields("Lst_mut_date").Value = Format(Date, "d-m-yyyy")
.Update
End With
rs.Update
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
MsgBox "De data is toegevoegd aan de objecten database"
Call UserForm_Initialize
On Error GoTo 0
Exit Sub
Errhandler_Van_Eijk_DB:
Set rs = Nothing
Set cnn = Nothing
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Toevoegen van data"
End Sub
Private Sub CommandButton3_Click() ''Bewerken database
ShowSheet "ImportPers"
'add error handling
On Error GoTo Errhandler:
If Me.TextBox00.Caption = "" Then
MsgBox "Een object selecteren.", _
vbOKOnly Or vbInformation, "Geen keuze gemaakt"
Exit Sub
End If
dbpath = DataSheet.Cells(7, 8).Value ''Lokatie "VanEijkPersoneel.accdb"
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbpath
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM ProjectenDb " & _
"WHERE ID = " & CLng(Me.TextBox00.Caption), ActiveConnection:=cnn, _
CursorType:=adOpenDynamic, LockType:=adLockOptimistic, _
Options:=adCmdText
If rs.EOF And rs.BOF Then
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
MsgBox "De geselecteerde persoon is niet gevonden!", vbCritical, "Fout met vinden van databasenummer"
Exit Sub
End If
On Error Resume Next
With rs
.Fields("Zoeknaam").Value = Me.TextBox0.Value
.Fields("Objectnaam").Value = Me.TextBox1.Value
.Fields("Objectadres").Value = Me.TextBox2.Value
.Fields("ObjectPostcode").Value = Me.TextBox3.Value
.Fields("ObjectPlaats").Value = Me.TextBox4.Value
.Fields("Cont_Object").Value = Me.TextBox5.Value
.Fields("Tel_Cont_Object").Value = Me.TextBox6.Value
.Fields("Mob__Cont_Object").Value = Me.TextBox7.Value
.Fields("Email__Cont_Object").Value = Me.TextBox8.Value
.Fields("Fact_naam").Value = Me.TextBox9.Value
.Fields("Fact_TAV").Value = Me.TextBox10.Value
.Fields("Fact_adres").Value = Me.TextBox11.Value
.Fields("Fact_Postcode").Value = Me.TextBox12.Value
.Fields("Fact_Postplaats").Value = Me.TextBox13.Value
.Fields("Fact_Email").Value = Me.TextBox14.Value
.Fields("Location").Value = Me.TextBox17.Value
.Fields("HistoryOff").Value = Replace(Me.TextBox15.Value, vbCrLf, " | ")
.Fields("HistoryWerk").Value = Replace(Me.TextBox16.Value, vbCrLf, " | ")
''.Fields("Id_omschr").Value = Me.Txtbox19.Value
''.Fields("extra").Value = Me.Txtbox90.Value
.Fields("lst_myt_by").Value = DataSheet.Cells(2, 3).Value
.Fields("Lst_mut_date").Value = Format(Date, "d-m-yyyy")
rs.Update
End With
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
'Inform the user that the macro was executed successfully.
MsgBox "De data is bijgewerkt", vbInformation, "Bijwerken geslaagd"
Call UserForm_Initialize
'error handler
On Error GoTo 0
Exit Sub
Errhandler:
'clear memory
Set rs = Nothing
Set cnn = Nothing
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure bewerken van personeelsdata"
End Sub
Private Sub CommandButton1_Click() ''Open tekeningen lokatie
If Me.CommandButton1.Caption = "Tekeningen" Then
i = Me.ListBox1.ListIndex
Me.ListBox1.Selected(i) = True
If Me.ListBox1.ListIndex = -1 Then Exit Sub
If Me.ListBox1.Column(18, i) = "" Then
MsgBox "Lokatie van tekeningen is niet bekend."
Exit Sub
Else
responce = MsgBox("Hiermee opent u de map waar de tekeningen instaan, weet u dit zeker?", vbYesNo, "Map openen")
If Not responce = vbYes Then Exit Sub
''''''OPENEN VAN FOLDERMAP
str_folder = "Z:\VanEijk\Daktekeningen objecten\" & Me.ListBox1.Column(18, i) ' folder to open
Call Shell("explorer.exe " & str_folder, vbNormalFocus)
Exit Sub
End If
Else
On Error GoTo Errhandler:
Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
diaFolder.AllowMultiSelect = False
diaFolder.Show
Me.TextBox17.Value = Split(diaFolder.SelectedItems(1), "objecten\")(1) & "\"
Set diaFolder = Nothing
End If
Exit Sub
Errhandler:
Set diaFolder = Nothing
Response = MsgBox("Er is geen lokatie geselecteerd", vbCritical, "Geen keuze gemaakt")
End Sub
Private Sub CommandButton4_Click() ''Plaats data in "Hoofdblad"
Application.ScreenUpdating = True
OffSheet1.Cells(11, 3).Value = Me.TextBox1.Value ''Objectnaam
OffSheet1.Cells(13, 3).Value = Me.TextBox2.Value ''Objectadres
OffSheet1.Cells(14, 3).Value = Me.TextBox3.Value ''Objectpostcode
OffSheet1.Cells(15, 3).Value = Me.TextBox4.Value ''Objectplaats
OffSheet1.Cells(16, 3).Value = Me.TextBox5.Value ''Cont. Object
OffSheet1.Cells(17, 3).Value = Me.TextBox6.Value ''Cont. tel.nr
OffSheet1.Cells(18, 3).Value = Me.TextBox7.Value ''Cont. mob.nr
OffSheet1.Cells(19, 3).Value = Me.TextBox8.Value ''Cont. e-mail
OffSheet1.Cells(21, 3).Value = Me.TextBox9.Value ''Fact. Objectnaam
OffSheet1.Cells(22, 3).Value = Me.TextBox10.Value ''Fact. T.a.v.
OffSheet1.Cells(23, 3).Value = Me.TextBox11.Value ''Fact. adres
OffSheet1.Cells(24, 3).Value = Me.TextBox12.Value ''Fact. postcode
OffSheet1.Cells(25, 3).Value = Me.TextBox13.Value ''Fact. plaats
OffSheet1.Cells(26, 3).Value = Me.TextBox14.Value ''Fact. e-mail
Unload Me
End Sub
Private Sub CommandButton6_Click() ''Clear textbox
ClearTextBox
Me.ListBox1.ListIndex = -1
Me.CommandButton5.Visible = True
End Sub
Private Sub CommandButton7_Click() '"Afsluiten
Unload Me
End Sub
Private Sub ListBox1_Click()
Me.CommandButton1.Visible = True
Me.CommandButton5.Visible = False
i = Me.ListBox1.ListIndex
Me.ListBox1.Selected(i) = True
Me.TextBox00.Caption = Me.ListBox1.Column(0, i)
For j = 1 To 15
Me.Controls("TextBox" & j - 1).Value = Me.ListBox1.Column(j + 2, i)
Next
Me.TextBox15.Text = Replace(Me.ListBox1.Column(19, i), " | ", vbCrLf)
Me.TextBox16.Text = Replace(Me.ListBox1.Column(20, i), " | ", vbCrLf)
Me.TextBox17.Value = Me.ListBox1.Column(18, i)
c00 = Split(Replace(Me.ListBox1.Column(19, i), "#", "|"), " | ")
For j = 0 To UBound(c00) Step 2
c01 = c01 & "|" & c00(j)
Next j
ComboBox1.List = Split(c01, "|")
If Me.ListBox1.Column(18, i) = "" Then
Me.CommandButton1.Caption = "Kies lokatie"
Me.TextBox17.Visible = True
Else
Me.CommandButton1.Caption = "Tekeningen"
Me.TextBox17.Visible = False
End If
If Me.ListBox1.Column(18, i) = "" Then
Me.ComboBox1.Visible = False
Me.CommandButton2.Visible = False
Else
Me.ComboBox1.Visible = True
Me.CommandButton2.Visible = True
End If
Me.lst_mod_by.Caption = Me.ListBox1.Column(1, i)
Me.lst_mod_date.Caption = Format(Me.ListBox1.Column(2, i), "d-m-yyyy")
End Sub
Sub SortObjectRng()
rw = Sheet8.Range("B" & Rows.Count).End(xlUp).row
Rng = "A3:U" & rw
Sheet8.Range(Rng).Sort Sheet8.Range("D2"), 1, , , , , , xlGuess
End Sub
Private Sub txtzoek_Change()
sFind = txtzoek.Text
If Len(sFind) = 0 Then
ListBox1.ListIndex = -1
ListBox1.TopIndex = 0
Else
For i = 0 To ListBox1.ListCount - 1
For j = 0 To Sheet8.Cells(2, Columns.Count).End(xlToLeft).Column - 1
If InStr(UCase(ListBox1.List(i, j)), UCase(sFind)) > 0 Then
ListBox1.TopIndex = i
ListBox1.ListIndex = i
End If
Next j
Next i
End If
End Sub
Sub ClearTextBox()
For Each Ctrl In Controls
If TypeName(Ctrl) = "TextBox" Or TypeName(Ctrl) = "ComboBox" Then
Ctrl.Value = ""
End If
Next Ctrl
Me.TextBox00.Caption = ""
End Sub
Private Sub UserForm_Activate()
Me.Tag = ActiveSheet.Name
If Me.Tag = "Hoofdblad" Then
OffSheet1.Select
Me.CommandButton4.Visible = True
Else
Sheet0.Select
Me.CommandButton4.Visible = False
End If
End Sub
Private Sub UserForm_Initialize()
ClearTextBox
ClearsheetImportObject
ImportObjectenBestand
SortObjectRng
rw = Sheet8.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).row
Set Rng = Sheet8.Range("A3:" & Split(Cells(1, Sheet8.Cells(2, Columns.Count).End(xlToLeft).Column).Address, "$")(1) & Sheet8.Range("A" & Rows.Count).End(xlUp).row)
With ListBox1
.Clear
.ColumnHeads = False
.ColumnCount = Rng.Columns.Count
.ColumnWidths = "0;0;0;100;0;0;0;75;0;0;0;0;0;0;0;0;0;0;0;0;0"
ReDim Myarray(Rng.Rows.Count, Rng.Columns.Count)
rw = 0
For i = 1 To Rng.Rows.Count
For j = 0 To Rng.Columns.Count
Myarray(rw, j) = Rng.Cells(i, j + 1)
Next
rw = rw + 1
Next
.List = Myarray
End With
Set Rng = Nothing
Me.CommandButton1.Visible = False
Me.CommandButton2.Visible = False
Me.ComboBox1.Visible = False
Me.TextBox17.Visible = False
End Sub