erikgutten
New member
- Joined
- Feb 6, 2018
- Messages
- 8
- Reaction score
- 0
- Points
- 0
Hi there.
I wonder about some issue that i met while testing my code on my multi tab form.
The case: I'm building a set of tabbed forms in a tabbed form, and i haven't declared it properly. Followed a tutorial, but the tutorial ain't cutting it, its not helping out when i got two tabs in a tab.
And all tabs have unique names
The tabs here are:
I wanna fill the combobox from named table header values: (Employees) i should perhaps change that to EmployeeTable for more ease. The excel sheet has also the same name.
And this cbo is in tab (empTabEdit) that is in tab (frmTabEmployees)
Can i fix this?
My code so far :
I wonder about some issue that i met while testing my code on my multi tab form.
The case: I'm building a set of tabbed forms in a tabbed form, and i haven't declared it properly. Followed a tutorial, but the tutorial ain't cutting it, its not helping out when i got two tabs in a tab.
And all tabs have unique names
The tabs here are:
I wanna fill the combobox from named table header values: (Employees) i should perhaps change that to EmployeeTable for more ease. The excel sheet has also the same name.
And this cbo is in tab (empTabEdit) that is in tab (frmTabEmployees)
Can i fix this?
My code so far :
Code:
Option Explicit
Private Sub cboSearchCriteria_Change()
FillcboSearchCriteria
End Sub
Private Sub cmdAddEmp_Click()
'declare dimentions for variables
Dim empDB As Worksheet
'This is for adding data from textboxes to the sheet
Dim Addme As Range
'These 2 are for option 1
Dim LastId As String, NewId As String
Dim N As Long
'Set variable
Set empDB = Employees
'Error handler
On Error GoTo errHandler:
'Set the variable for destination in option 2
Set Addme = empDB.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
'holding in memory and prevent screen flicker
Application.ScreenUpdating = False
If Me.txtEmpFirstname = "" Or Me.txtEmpLastname = "" Or Me.txtEmpHomeAdress = "" Then
MsgBox "Hei du, din slask, du må registrere all tilgjengelig informasjon"
Exit Sub
End If
'send data to the database
With empDB
'add the unique reference Id, then all other
'Option 1 Code to make new ID
N = Cells(Rows.Count, "A").End(xlUp).Row
LastId = Cells(N, "A").Value
NewId = "E-id 100" & CLng(Mid(LastId, 8)) + 1
'Addme.Offset(0, 1).Value = Me.txtEmpFirstname
Addme.Offset(0, 2).Value = Me.txtEmpFirstname
Addme.Offset(0, 3).Value = Me.txtEmpMiddlename
Addme.Offset(0, 4).Value = Me.txtEmpLastname
Addme.Offset(0, 5).Value = Me.txtEmpCellular
Addme.Offset(0, 6).Value = Me.txtEmpHomePhone
Addme.Offset(0, 8).Value = Me.txtEmpEmail
Addme.Offset(0, 9).Value = Me.txtEmpHomeAdress
Addme.Offset(0, 10).Value = Me.txtEmpPostNo
Addme.Offset(0, 11).Value = Me.txtEmpPostOffice
Addme.Offset(0, 12).Value = Me.txtEmpAccount
Addme.Offset(0, 13).Value = Me.txtEmpPossition
Addme.Offset(0, 14).Value = Me.txtEmpSalary
Addme.Offset(0, 15).Value = Me.txtEmpPossition
Addme.Offset(0, 16).Value = Me.DTPickerEmpHired
End With
'Sort the data by last name / surname
empDB.Select
With empDB
.Range("a2:q2000").Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlGuess
End With
'Clear the values after entry
Clear
MsgBox "Du har greid det, registrere alle nødvendige data, ikke dum du!"
'return to interface form
empTabAddNew.Select
On Error GoTo 0
Exit Sub
errHandler:
'if error occurs, then show where the error is occuring
MsgBox "Feil " & Err.Number & _
" (" & Err.Description & ")in procedure cmdEmpClear_Click of Form frmOrderSystem"
End Sub
Sub Clear()
Dim ctl As Control
For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "TextBox"
ctl.Text = ""
Case "ListBox"
ctl.RowSource = ""
Case "ComboBox"
ctl.Value = ""
End Select
Next ctl
End Sub
Private Sub cmdEmpClearAll_Click()
'clear all controls
Clear
End Sub
Sub FillcboSearchCriteria()
'This is to fill the combobox with data form table headers
Dim Cell As Range
Dim i As Single
'Dim myobj As Object
Set Cell = Workshhets("Employees").Range("Employees")
Form("empTabEdit").cboSearchCriteria.Clear
With cboSearchCriteria
.AddItem "All Columns"
End With
For i = 1 To Cell.ListObject.Range.Columns.Count
Form("empTabEdit").cboSearchCriteria.AddItem Cell.ListObject.Range.Cells(1, i)
Next i
End Sub
Private Sub cmdGetEmp_Click()
'declare the dimention for the variables
Dim Criteria As Range
Dim FindMe As Range
Dim empDB As Worksheet
'Errorhandler
On Error GoTo errHandler:
'Object variable
Set empDB = Employees
'keep in memory
Application.ScreenUpdating = False
'********************************
'If header is selected, add the criteria
If Me.cboSearchCriteria.Value <> "All_Columns" Then
If Me.txtEmpSearch = "" Then
'here is where i stopped following the tutorial, that were reffering to another table, not what i wanna do
End Sub