Listbox y excel con visual basic
Este código que te pongo ahora con un listbox, dos textbox y cuatro botones, es el que estoy utilizando para hacer mi aplicación, también consta de una tabla en access.
Lo que he intentado por todos los medios y no lo consigo es crear un botón que me mande los datos desde el textbox a una casilla espscifica de la página de excel que tengo creada.
Dim db As Database
Dim rs As Recordset
Dim ws As Workspace
Dim max As Long
Dim I As Long
Dim errormsg
Dim dbedit As Boolean
Private Sub cmdcancel_Click()
txtSurname.Text = vbNullString
txtSurname.Enabled = False
Text1.Text = vbNullString
Text1.Enabled = False
cmdsave.Enabled = False
cmdcancel.Enabled = False
cmdend.Enabled = True
cmdEdit.Enabled = True
Set rs = db.OpenRecordset("tbldata", dbOpenTable)
list
End Sub
Private Sub cmdEdit_Click()
txtSurname.Enabled = True
Text1.Enabled = True
cmdEdit.Enabled = False
cmdend.Enabled = False
cmdsave.Enabled = True
cmdcancel.Enabled = True
dbedit = True
End Sub
Public Function edit()
If txtSurname.Text = vbNullString Or _
Text1.Text = vbNullString Then
errormsg = MsgBox("All Fields Must Contain Data", vbCritical, "Error")
Exit Function
End If
rs.edit
rs("surname") = txtSurname.Text
rs("hola") = Text1.Text
rs.Update
txtSurname.Text = vbNullString
txtSurname.Enabled = False
Text1.Text = vbNullString
Text1.Enabled = False
cmdsave.Enabled = True
cmdcancel.Enabled = True
cmdend.Enabled = True
cmdEdit.Enabled = True
Set rs = db.OpenRecordset("tbldata", dbOpenTable)
list
End Function
Private Sub cmdend_Click()
db.Close
End
End Sub
Private Sub cmdsave_Click()
If dbedit = True Then
Call edit
End If
End Sub
Private Sub Form_Load()
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(App.Path & "\Database.mdb")
Set rs = db.OpenRecordset("tbldata", dbOpenTable)
list
End Sub
Private Function list()
rs.MoveLast
rs.MoveFirst
max = rs.RecordCount
rs.MoveFirst
lstdata.Clear
For I = 1 To max
lstdata.AddItem rs("surname")
rs.MoveNext
Next I
End Function
Private Sub lstdata_Click()
Set rs = db.OpenRecordset("Select * from tbldata where surname = '" & Trim(lstdata.list(lstdata.ListIndex)) & "'")
rs.MoveFirst
Text1.Text = rs("hola")
txtSurname.Text = rs("Surname")
End Sub
¿Puedes ayudarme en esto?
Un saludo
Lo que he intentado por todos los medios y no lo consigo es crear un botón que me mande los datos desde el textbox a una casilla espscifica de la página de excel que tengo creada.
Dim db As Database
Dim rs As Recordset
Dim ws As Workspace
Dim max As Long
Dim I As Long
Dim errormsg
Dim dbedit As Boolean
Private Sub cmdcancel_Click()
txtSurname.Text = vbNullString
txtSurname.Enabled = False
Text1.Text = vbNullString
Text1.Enabled = False
cmdsave.Enabled = False
cmdcancel.Enabled = False
cmdend.Enabled = True
cmdEdit.Enabled = True
Set rs = db.OpenRecordset("tbldata", dbOpenTable)
list
End Sub
Private Sub cmdEdit_Click()
txtSurname.Enabled = True
Text1.Enabled = True
cmdEdit.Enabled = False
cmdend.Enabled = False
cmdsave.Enabled = True
cmdcancel.Enabled = True
dbedit = True
End Sub
Public Function edit()
If txtSurname.Text = vbNullString Or _
Text1.Text = vbNullString Then
errormsg = MsgBox("All Fields Must Contain Data", vbCritical, "Error")
Exit Function
End If
rs.edit
rs("surname") = txtSurname.Text
rs("hola") = Text1.Text
rs.Update
txtSurname.Text = vbNullString
txtSurname.Enabled = False
Text1.Text = vbNullString
Text1.Enabled = False
cmdsave.Enabled = True
cmdcancel.Enabled = True
cmdend.Enabled = True
cmdEdit.Enabled = True
Set rs = db.OpenRecordset("tbldata", dbOpenTable)
list
End Function
Private Sub cmdend_Click()
db.Close
End
End Sub
Private Sub cmdsave_Click()
If dbedit = True Then
Call edit
End If
End Sub
Private Sub Form_Load()
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(App.Path & "\Database.mdb")
Set rs = db.OpenRecordset("tbldata", dbOpenTable)
list
End Sub
Private Function list()
rs.MoveLast
rs.MoveFirst
max = rs.RecordCount
rs.MoveFirst
lstdata.Clear
For I = 1 To max
lstdata.AddItem rs("surname")
rs.MoveNext
Next I
End Function
Private Sub lstdata_Click()
Set rs = db.OpenRecordset("Select * from tbldata where surname = '" & Trim(lstdata.list(lstdata.ListIndex)) & "'")
rs.MoveFirst
Text1.Text = rs("hola")
txtSurname.Text = rs("Surname")
End Sub
¿Puedes ayudarme en esto?
Un saludo
1 Respuesta
Respuesta de denciso
1