Private Sub Button2_Released()
Dim objcon As New ADODB.Connection
Dim rst As New ADODB.Recordset
'Creating the DB connection string
'Please change the below connection string as per your server and
'database being used.
objcon.connectionString = Connection
'Opening the connection
objcon.Open objcon.connectionString
MsgBox "Connection opened"
Set rst.ActiveConnection = objcon
rst.ActiveConnection = objcon
rst.Source = "Select * From dbo.ORDERP"
rst.Open
'Create a new textbox control
Dim txtBox As New TextBox
'Set the textbox's Text property to the contents of the recordset
txtBox.Text = rst.Fields("ORP").value
'Add the textbox to the form
Me.Controls.Add txtBox
'Move the textbox to the desired location on the form
txtBox.Top = 100
txtBox.Left = 100
rst.MoveNext
While Not rst.EOF
'Create a new textbox control
Dim txtBox As New TextBox
'Set the textbox's Text property to the contents of the recordset
txtBox.Text = rst.Fields("ORP").value
'Add the textbox to the form
Me.Controls.Add txtBox
'Move the textbox to the desired location on the form
txtBox.Top = txtBox.Top + 20
txtBox.Left = 100
rst.MoveNext
Wend
'Close the recordset and connection
rst.Close
objcon.Close
Set rst = Nothing
Set objcon = Nothing
MsgBox "Connection closed"
End Sub
Private Sub Button2_Released()
Dim objcon As New ADODB.Connection
Dim rst As New ADODB.Recordset
'Creating the DB connection string
'Please change the below connection string as per your server and
'database being used.
objcon.connectionString = Connection
'Opening the connection
objcon.Open objcon.connectionString
MsgBox "Connection opened"
Set rst.ActiveConnection = objcon
rst.ActiveConnection = objcon
rst.Source = "Select * From dbo.ORDERP"
rst.Open
'Create a new textbox control
Dim txtBox As New TextBox
'Set the textbox's Text property to the contents of the recordset,
'separated by newlines
txtBox.Text = rst.Fields("ORP").value & vbCrLf
'Add the textbox to the form
Me.Controls.Add txtBox
'Move the textbox to the desired location on the form
txtBox.Top = 100
txtBox.Left = 100
rst.MoveNext
While Not rst.EOF
'Append the contents of the "ORP" field to the textbox,
'separated by a newline
txtBox.Text = txtBox.Text & rst.Fields("ORP").value & vbCrLf
rst.MoveNext
Wend
'Close the recordset and connection
rst.Close
objcon.Close
Set rst = Nothing
Set objcon = Nothing
MsgBox "Connection closed"
End Sub
El evento "Released" del botón "Button33" se ejecuta cuando el usuario hace clic en el
botón.
El código entra en un bloque de error.
Se declaran las variables row, saveOk, combobox y comboboxCount.
La variable combobox se establece en el combobox "Cuadrocombinado4".
La variable comboboxCount se establece en el número de elementos del combobox.
Se inicia un bucle For que recorre todos los elementos del combobox.
En cada iteración del bucle, se llama a la función kernel.writeTag() para guardar el
valor del elemento actual del combobox en el kernel.
Si la función kernel.writeTag() devuelve False, se sale del bucle.
Al final del bucle, se comprueba si todos los elementos del combobox se guardaron
correctamente.
Si todos los elementos se guardaron correctamente, se muestra un mensaje de
confirmación al usuario.
Si se produjo un error, se llama a la función globalErrHandler() para manejar el
error.
Variables:
row: Variable que almacena el índice del elemento actual del combobox.
saveOk: Variable que indica si la función kernel.writeTag() se realizó
correctamente.
combobox: Variable que almacena el combobox "Cuadrocombinado4".
comboboxCount: Variable que almacena el número de elementos del combobox.
Funciones:
kernel.writeTag(): Función que escribe un tag en el kernel.
globalErrHandler(): Función que maneja los errores.