Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Dim gd As New DataGridView
gd.Name = "gd"
Me.Controls.Add(gd)
01 Option Explicit
02 `WithEvents is a way tell the program to
03 `respect all the events that are associated
04 `a CommandButton such as the click event.
05 Private WithEvents cmdMyButton As CommandButton
06
07 Private Sub Form_Load()
08 Set cmdButton = Controls.Add("VB.CommandButton", _ "Button")
09 With mdButton
10 .Visible = True
11 .Width = 3000
12 .Caption = "A real surprise"
12 .Top = 1000
14 .Left = 1000
15 End With
16 End Sub
Option Explicit
' If you are adding an ActiveX control at run-time that is
' not referenced in your project, you need to declare it
' as VBControlExtender.
Dim WithEvents ctlDynamic As VBControlExtender
Dim WithEvents ctlText As VB.TextBox
Dim WithEvents ctlCommand As VB.CommandButton
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = conn
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Properties("IRowsetIdentity") = True 'remove comment to display data
.Open statement, , , , adCmdText
End With
Me.Controls.Add "MSDataGridLib.DataGrid", "DataGrid2"
Set DataGrid2.DataSource = rs
Me.Controls.Add "MSDataGridLib.DataGrid", "DataGrid2"
Dim DataGrid2 As DataGrid
Set DataGrid2 = Me.Controls(Me.Controls.Count-1)
Set DataGrid2.DataSource = rs
Option Explicit
Dim db_file As String
Dim statement As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim Time1 As Date
Dim Time2 As Date
Private Sub MDIForm_Load()
MDIForm1.Height = Screen.Height
MDIForm1.Width = Screen.Width
MDIForm1.Left = 0
MDIForm1.Top = 0
' Get the data.
db_file = App.Path
If Right$(db_file, 1) <> "\" Then db_file = db_file & _
"\"
db_file = db_file & "topping_jobs.mdb"
' Open a connection.
Set conn = New ADODB.Connection
conn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & db_file & ";" & _
"Persist Security Info=False"
conn.Open
' Select the data.
Time1 = Format(Now(), "dd/mm/yyyy hh:n")
Time1 = DateAdd("h", -4, Time1)
Time2 = DateAdd("h", 8, Time1)
Time1 = Format(Time1, "dd/mm/yyyy hh:nn")
Time2 = Format(Time2, "dd/mm/yyyy hh:nn")
statement = "SELECT format(Docket.Date,'dd/mm/yyyy') AS [Date], format(Docket.Time,'hh:mm') " & _
" as [Time], Docket.Name, Docket.From, Docket.To, Docket.Notes," & _
" format(Docket.Price,'Currency') AS Price, Controllers.Controller, " & _
"Drivers.DriverNumber+' ('+Drivers.FirstName+')' AS DriverNumber, Vehicle.Vehicle, " & _
"AccountCustomers.AccountNumber+' ('+AccountCustomers.CompanyName+')' AS AccountNumber, " & _
"IIf([Docket.cancelled]=False,'No','Yes') As Cancelled FROM Vehicle " & _
"INNER JOIN (Drivers RIGHT JOIN (AccountCustomers RIGHT JOIN " & _
"(Controllers INNER JOIN Docket ON Controllers.ID = Docket.Controller) " & _
"ON AccountCustomers.CustomerID = Docket.AccountID) ON Drivers.EmployeesID = Docket.Driver_No) " & _
"ON Vehicle.ID = Docket.Vehicle WHERE Docket.Date > #" _
& Format(Time1, "dd/mm/yyyy hh:n") & "# AND Docket.Date < #" & Format(Time2, "dd/mm/yyyy hh:n") & "# ORDER BY [Docket.Time];"
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = conn
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Properties("IRowsetIdentity") = True 'remove comment to display data
.Open statement, , , , adCmdText
End With
Me.Controls.Add "MSDataGridLib.DataGrid", "DataGrid2"
Dim DataGrid2 As DataGrid
'Set DataGrid2 = Me.Controls(Me.Controls.Count - 1)
Set DataGrid2 = Me.Controls("DataGrid2")
Set DataGrid2.DataSource = rs
'rs.Close
'conn.Close
End Sub
Me.Controls.Add "MSDataGridLib.DataGrid", "DataGrid1"
Dim DataGrid1 As DataGrid
Set DataGrid1 = Me.Controls(Me.Controls.Count - 1)
'Set DataGrid1 = Me.Controls("DataGrid1")
DataGrid1.Visible = True
MsgBox (DataGrid1.Visible & " " & rs.RecordCount)
Set DataGrid1.DataSource = rs