Visual Basic - Ayuda!! VB-ACCESS

Life is soft - evento anual de software empresarial
 
Vista:

Ayuda!! VB-ACCESS

Publicado por Paty Luna (2 intervenciones) el 01/11/2005 22:42:04
Hola, estoy haciendo un programa con vb y access y no puedo hacer k los botones
de "primer, anterior, siguiente, último" funcionen. Me dice k no se puede actualizar la base y k no se pueden llenar las filas hacia atrás... Soy novata en VB y la verdad no se como hacerle, aqui les va mi código haber si alguien me puede ayudar.

1,000,000 de Gracias.!!!!!

MARCA ERRORES EN EL RECORDSET (MOVE)

Attribute VB_Name = "ptkmod"
Option Explicit
Global db_file As String
Global conn As New ADODB.Connection
Global rs As ADODB.Recordset
Global id As String
Global statement As String

Public Function open_ptkconn()
' Open the database.
db_file = App.Path
If Right$(db_file, 1) <> "\" Then db_file = db_file & _
"\"
db_file = db_file & "PTK.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

End Function

Public Sub open_rscli()
Call open_ptkconn
statement = "SELECT * FROM Clientes"
Set rs = conn.Execute(statement)
End Sub

**********************
Private Sub Form_Load()
Dim i As Long
Call open_ptkconn
Call open_rscli

For i = 0 To 4
Set txt(i).DataSource = rs
Next
txt(0).DataField = "nombre"
txt(1).DataField = "direccion"
txt(2).DataField = "tel"
txt(3).DataField = "Empresa"
txt(4).DataField = "num_tran"
cmdUpdate.Enabled = False
End Sub

Private Sub cmdAdd_Click()
Call open_ptkconn
Call open_rscli
With rs
.AddNew
.Update
End With
End Sub

Private Sub cmdClose_Click()
Load frmMenu
frmMenu.Show
Unload Me
End Sub

Private Sub cmdDelete_Click()
Call open_ptkconn
Call open_rscli
MsgBox ("Está seguro de que desea borrar este registro?")
If confirm = vbYes Then
rs.Delete
MsgBox "Registro Eliminado!"
Else
MsgBox "Registo no Eliminado!"
End If
End Sub

Private Sub cmdF_Click()
Call open_ptkconn
Call open_rscli
rs.MoveFirst
End Sub

Private Sub cmdL_Click()
Call open_ptkconn
Call open_rscli
rs.MoveLast
End Sub

Private Sub cmdP_Click()
Call open_ptkconn
Call open_rscli
If Not BOF Then
rs.MovePrevious
Else
MsgBox "Este es el primer registro"
End If
End Sub

Private Sub cmN_Click()
Call open_ptkconn
Call open_rscli
rs.MoveNext
End Sub

**********************


VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form frmCliente
Caption = "Cliente"
ClientHeight = 5895
ClientLeft = 45
ClientTop = 435
ClientWidth = 9885
LinkTopic = "Form1"
ScaleHeight = 5895
ScaleWidth = 9885
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txttra
DataField = "num_tran"
DataSource = "Adodc1"
Height = 495
Left = 7080
TabIndex = 10
Top = 360
Width = 735
End
Begin MSAdodcLib.Adodc Adodc1
Height = 372
Left = 1080
Top = 2760
Width = 4092
_ExtentX = 7223
_ExtentY = 661
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 2
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\PTK\PTK.mdb;Persist Security Info=False"
OLEDBString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\PTK\PTK.mdb;Persist Security Info=False"
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = ""
Password = ""
RecordSource = "clientes"
Caption = ""
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
Begin VB.CommandButton cmdCont
Caption = "&Ir a Contrato"
Height = 492
Left = 6480
TabIndex = 9
Top = 4440
Width = 1572
End
Begin VB.CommandButton cmdCancelar
Caption = "&Cancelar"
Height = 492
Left = 8400
TabIndex = 8
Top = 4440
Width = 972
End
Begin VB.TextBox txtEmp
DataField = "empresa"
DataSource = "Adodc1"
Height = 372
Left = 2400
TabIndex = 7
Top = 2160
Width = 3252
End
Begin VB.TextBox txtDir
DataField = "direccion"
DataSource = "Adodc1"
Height = 372
Left = 2400
TabIndex = 6
Top = 1560
Width = 3252
End
Begin VB.TextBox txtTel
DataField = "tel"
DataSource = "Adodc1"
Height = 372
Left = 2400
TabIndex = 5
Top = 960
Width = 3252
End
Begin VB.TextBox txtNom
DataField = "nombre"
DataSource = "Adodc1"
Height = 372
Left = 2400
TabIndex = 4
Top = 360
Width = 3252
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "Empresa:"
Height = 192
Left = 1080
TabIndex = 3
Top = 2160
Width = 696
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "Dirección:"
Height = 192
Left = 1080
TabIndex = 2
Top = 1560
Width = 720
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "Teléfono:"
Height = 192
Left = 1080
TabIndex = 1
Top = 960
Width = 684
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Nombre:"
Height = 192
Left = 1080
TabIndex = 0
Top = 360
Width = 624
End
End
Attribute VB_Name = "frmCliente"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdCancelar_Click()
Unload Me
frmMenú.Show

End Sub

Private Sub cmdCont_Click()
Adodc1.Recordset.AddNew

End Sub

Private Sub Form_Load()
frmCliente.Cls
End Sub
***************
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Ayuda!! VB-ACCESS

Publicado por Arnaldo (53 intervenciones) el 01/11/2005 23:39:55
Hola, te muestro una forma con la que yo accedia a baces de datos Acces.

Dim Cn as New ADODB.Connection
Dim Rs as New ADODB.Recordset
Dim SQL as String

Private Sub Fom_Load ()

SQL= "SELECT nombre, direccion, tel, Empresa, num_tran " _
& "FROM Clientes; "
cn.Open "DSN=Nomb_Archivo.mdb"
rs.CursorType = adOpenStatic
rs.LockType = adLockBatchOptimistic
rs.Open SQL, cn, , adLockBatchOptimistic

If Rs.EOF = False Then
Rs.MoveFirst
ActualizarDatos
end if
End Sub

Private Sub Command1_click 'Mover adelante
If rs.BOF = True And rs.EOF = False Then
rs.MoveNext
ActualizarDatos
End If
End Sub

Private Sub Command2_click 'Mover atras
If rs.BOF = True And rs.EOF = False Then
Rs.MovePrevius
ActualizarDatos
end if
End Sub

Private Sub Command3_click 'Mover Ultimo
If rs.BOF = True And rs.EOF = False Then
Rs.MoveLast
ActualizarDatos
end if
End Sub

Private Sub Command4_click 'Mover Primero
If rs.BOF = True And rs.EOF = False Then
Rs.MoveFirst
ActualizarDatos
end if
End Sub

Private Sub Fom_UnLoad ()
Rs.close
cn.close
Set Rs = Nothing
End Sub

Public Sub ActualizarDatos
txt(0).DataField = Rs.Fields("nombre") .value
txt(1).DataField = Rs.Fields("direccion").value
txt(2).DataField = Rs.Fields(2).value 'Tel
txt(3).DataField = Rs.Fields(3).value 'Empresa
txt(4).DataField = Rs.Fields(4).value 'num_tran
End Sub

No lo probe puedo tener algunos errores de sintaxis, de reconosimiento inmediatos, desde VB. En este momento no tengo VB para provarlo.
Espero haberte ayudado.

Arnaldo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Gracias!!!

Publicado por Paty Luna (2 intervenciones) el 02/11/2005 15:21:19
Hola , Voy a usar el código para ver si funciona. muchas Gracias por responder.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar