-1
Private Sub Command1_Click()
Dim contador As Integer
Dim tabla As TableDef
Dim columna As Field
Dim baseDeDatos As Database
Dim directorioDB As String
Set tabla = baseDeDatos.OpenTable("Empleados")
tabla.AddNew
tabla!Legajo = Text1.Text
tabla.AddNew
tabla!Nombre = Text2.Text
If Text3.Text > 19 And Text3.Text < 51 Then
    tabla.AddNew
    tabla!Edad = Text3.Text
    Label4.Caption = "Terminado"
Else
    Label4.Caption = "Registro no cargado. Rango de edad entre 20 y 50 años"
End If
tabla.Update
If contador = 10 Then
    Command1.Caption = "Cargados 10 registros"
Else
    contador = contador + 1
End If
End Function

Private Sub Form_Load()
Dim tabla As TableDef
Dim columna As Field
Dim baseDeDatos As Database
Dim directorioDB As String
Set archivo = New FileSystemObject

If Not archivo.FileExists("C:\Users\tam45949\Desktop\tp2programacion2.mdb") Then
    Set baseDeDatos = DBEngine.Workspaces(0).CreateDatabase("C:\Users\tam45949\Desktop\tp2programacion2.mdb", dbLangSpanish)
End If

Set baseDeDatos = OpenDatabase("C:\Users\tam45949\Desktop\tp2programacion2.mdb")
Set tabla = baseDeDatos.CreateTableDef("Empleados")
Set columna1 = tabla.CreateField("Legajo", dbInteger)
tabla.Fields.Append (columna1)
Set columna2 = tabla.CreateField("Nombre", dbText, 30)
tabla.Fields.Append (columna2)
Set columna3 = tabla.CreateField("Edad", dbInteger)
tabla.Fields.Append (columna3)
baseDeDatos.TableDefs.Append tabla
End Sub

Private Sub Form_Terminate()
    tabla.Close
    baseDeDatos.Close
End Sub

Link to the library list

I don't know what is the problem with the code and i searched on the net a couple of hours and i still can't find se solution. The problem should be in the Addnew function, i guess there is a missing library. Hope you can help me, i'm new with v b 6.0. Thanks!.

sepp2k
  • 363,768
  • 54
  • 674
  • 675

1 Answers1

1

Probably you don't have a correct reference to DAO (or ADO), check in project references if you are able to use Microsoft Data Object (DAO) or ADO with recordset.

The method AddNew in general is the old way to work with recordsets and common in DAO code. I believe that you can move the code to use ADO and improve your statements with update , insert and delete and not using AddNew or Edit

MCunha98
  • 81
  • 3
  • 12