We saw in this article how we can insert data into excel database from textboxes and combo boxes in userform with visual basic. Now because we developed this graphic interface, of course we want the user to use it without exiting it. I would like to show you how we can display the data from the submitted excel database.
We've set up everything in the last article (how to open the graphic interface, insert the code, buttons, textboxes, etc).
Example data set:
Nr_inregistrare | Nume Judet | Localitate | Strada | Numar | CNP_CUI | P_abs | Stadiu | Data | Data1 | Lucrare | |
1 | Albahar Ilfov | Costesti | Pinului | 27 | 6656454 | 16 | Plan atasat | 5/20/2018 | Client ATR | 5 | |
2 | Alistar Bucuresti | Sector 1 | Dudului | 28 | 213837 | 24 | Avize CU obtinute | 5/20/2018 | Dezvoltator | 6 | |
3 | Total Ilfov | Rosu | Lidului | 29 | 181382 | 1342 | Avize CU obtinute | 5/20/2018 | Deviere | 7 | |
4 | Compact Ilfov | Cochirleni | Buriceni | 30 | 412124412 | 5 | Cerere inregistrata | 5/20/2018 | Client ATR | 7 | |
5 | Genoriu Ilfov | Coco | Bubu | 2 | 412124412 | 5 | Cerere inregistrata | 5/20/2018 | Client ATR | 7 |
Code:
Private Sub Verifica_Click()
Dim dDate As Date
Dim Interval As Range
Dim Rng As Range
Dim Lookup As String
Dim Done As Boolean
On Error GoTo ErrHand
If Not TextBox1.Value = "" Then
With Application.WorksheetFunction
d = .Match(CLng(TextBox1.Value), Worksheets("Sheet1").Range("A:A"), 0)
End With
Else
ErrHand:
MsgBox ("Number of request incorrect")
For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "TextBox"
ctl.Text = ""
Case "CheckBox", "OptionButton", "ToggleButton"
ctl.Value = False
ctl.BackColor = &HC0E0FF
Case "ComboBox", "ListBox"
ctl.ListIndex = -1
End Select
Next ctl
GoTo ErrorHandler
End If
If WorksheetFunction.CountIf(Sheets("Sheet1").Range("A:A"), Me.TextBox1) = 0 Then
MsgBox "The request does not exist"
Me.TextBox1.Value = ""
Exit Sub
End If
With Me
lrCD1 = Sheets("Sheet1").Range("L" & Rows.Count).End(xlUp).Row
'Vlookup using field Reg1 as the source (ex: request number in table)
Dim Jd
Dim loc
Dim str
Dim nr
Jd = Cells(d, 3)
loc = Cells(d, 4)
str = Cells(d, 5)
nr = Cells(d, 6)
TextBox2 = Cells(d, 2)
TextBox3 = Cells(d, 11)
TextBox4 = Jd & "," & loc & "," & str & "," & nr
TextBox5 = Cells(d, 7)
'dDate = DateSerial(Year(Date), Month(Date), Day(Date))
' TextBox5.Value = Format(Reg4.Value, "dd/mm/yyyy")
' dDate = TextBox5.Value
TextBox7= Cells(d, 8)
TextBox6 = Cells(d, 9)
End With
ErrorHandler:
End Sub
PS:For help or collaboration contact me in the comments below or privately.:-)
Comments
Post a Comment