Sei sulla pagina 1di 6

Comandos de Visual Basic

Buscar:

Dim mensaje As Variant


Dim SearchStr As Variant
mensaje = "Introduzca el nombre del Equipo."
'obtiene la cadena que se utilizará en la búsqueda del título
SearchStr = InputBox(mensaje, "Búsqueda del Equipo")
Data1.Recordset.Index = "Descripcion" 'usa título
Data1.Recordset.Seek ">=", SearchStr 'y busca
If Data1.Recordset.NoMatch Then 'si no encuentra ninguno
Data1.Recordset.MoveFirst 'va al primer registro.
End If

Colocarse en
Text1.SetFocus

Dim strName As String


Dim dDate As Date
Dim lngItem As Long

'Handle User click on column header


If ColumnHeader.Text = "Name" Then 'User clicked on Name
header
ListView1.Sorted = True 'Use default sorting to sort the
ListView1.SortKey = 0 'items in the list
Else
ListView1.Sorted = False 'User clicked on the Date header
'Use our sort routine to sort
'by date
SendMessage ListView1.hWnd, LVM_SORTITEMS,
ListView1.hWnd, AddressOf CompareDates
End If

'Refresh the ListView before writing the data


ListView1.Refresh

'Loop through the items in the List to print them out in


'sorted order.
'NOTE: You are looping through the ListView control because when
'sorting by date the ListItems collection won't be sorted.

For lngItem = 0 To ListView1.ListItems.Count - 1


ListView_GetListItem lngItem, ListView1.hWnd, strName, dDate
Next

Private Sub DBGrid1_RowColChange(LastRow As Variant, ByVal


LastCol As Integer)

Dim bk1 As String, bk2 As String, lastname As String


bk1 = LastRow
bk2 = DBGrid1.Bookmark

If bk1 <> bk2 Then


Screen.MousePointer = vbHourglass

lastname = Data1.Recordset("Last")
Data2.RecordSource = "SELECT * FROM OPUS WHERE
LAST = " _
& Chr$(34) & lastname & Chr$(34)
Data2.Refresh
Screen.MousePointer = vbDefault
End If

Data1.Recordset.MoveLast
Data1.ReadOnly = False
DBGrid1.Row = DBGrid1.Row + 1
DBGrid1.SetFocus

Dim mensaje As Variant


Dim Reply As Variant
mensaje = "Introduzca un nuevo registro y pulse el botón flecha
izquierda."
Reply = MsgBox(mensaje, vbOKCancel, "Añadir Registro")
If Reply = vbOK Then 'si el usuario pulsa Aceptar
'Text2.SetFocus 'mueve el cursor al cuadro de título
Data1.Recordset.AddNew 'y obtén un nuevo registro
'define el campo PubID como 14 (este campo es necesario
'Data1.Recordset.PubID = 14 'para Biblio.mdb)
End If

If Data1.Recordset.EOF = True Then


Data1.Recordset.MovePrevious
End If
DBGrid1.SetFocus

Borrar

Dim mensaje As Variant


Dim respuesta As Variant
mensaje = "¿Seguro que quiere borrar este registro?"
respuesta = MsgBox(mensaje, vbOKCancel, "Borrar registro")
If respuesta = vbOK Then 'si el usuario pulsa Aceptar
Data1.Recordset.Delete 'borra el registro actual
Data1.Recordset.MoveNext 'mueve al siguiente registro
End If
Pass Word

Private Declare Function EnableWindow Lib "user32" (ByVal hWnd


As Integer, ByVal aBOOL As Integer) As Integer
Private Declare Function IsWindowEnabled Lib "user32" (ByVal
hWnd As Integer) As Integer
Private Declare Function GetMenu Lib "user32" (ByVal hWnd As
Integer) As Integer
Private Declare Function FindWindow Lib "user32" Alias
"FindWindowA" (ByVal lpClassName As String, ByVal
lpWindowName As String) As Long
Private Declare Function SystemParametersInfo Lib "user32" Alias
"SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam
As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long

Private TaskBarhWnd As Long


Private IsTaskBarEnabled As Integer
Private TaskBarMenuHwnd As Integer
Sub FastTaskSwitching(bEnabled As Boolean)
Dim X As Long, bDisabled As Long
bDisabled = Not bEnabled
X = SystemParametersInfo(97, bDisabled, CStr(1), 0)
End Sub

Public Sub DisableTaskBar()


Dim EWindow As Integer
TaskBarhWnd = FindWindow("Shell_traywnd", "")
If TaskBarhWnd <> 0 Then
'check to see if window is enabled
EWindow = IsWindowEnabled(TaskBarhWnd)

If EWindow = 1 Then 'need to disable it


IsTaskBarEnabled = EnableWindow(TaskBarhWnd, 0)
End If
End If
End Sub

Public Sub EnableTaskBar()


If IsTaskBarEnabled = 0 Then
IsTaskBarEnabled = EnableWindow(TaskBarhWnd, 1)
End If
End Sub
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As
ComctlLib.ColumnHeader)
Dim strName As String
Dim dDate As Date
Dim lngItem As Long

'Handle User click on column header


If ColumnHeader.Text = "Name" Then 'User clicked on Name
header
ListView1.Sorted = True 'Use default sorting to sort the
ListView1.SortKey = 0 'items in the list
Else
ListView1.Sorted = False 'User clicked on the Date header
'Use our sort routine to sort
'by date
SendMessage ListView1.hWnd, LVM_SORTITEMS,
ListView1.hWnd, AddressOf CompareDates
End If

'Refresh the ListView before writing the data


ListView1.Refresh

'Loop through the items in the List to print them out in


'sorted order.
'NOTE: You are looping through the ListView control because when
'sorting by date the ListItems collection won't be sorted.

For lngItem = 0 To ListView1.ListItems.Count - 1


ListView_GetListItem lngItem, ListView1.hWnd, strName, dDate
Next

End Sub

______________________________________

Private Sub DBGrid1_RowColChange(LastRow As Variant, ByVal


LastCol As Integer)
Dim bk1 As String, bk2 As String, lastname As String
bk1 = LastRow
bk2 = DBGrid1.Bookmark

If bk1 <> bk2 Then


Screen.MousePointer = vbHourglass

' If the row has changed in DBGrid1, make sure that


' DBGrid2 displays only compositions by the composer at
' the new row of DBGrid1.

lastname = Data1.Recordset("Codigo")
Data2.RecordSource = "SELECT * FROM OPUS WHERE
LAST = " _
& Chr$(34) & lastname & Chr$(34)
Data2.Refresh
Screen.MousePointer = vbDefault
End If

End Sub

Potrebbero piacerti anche