I have a MS Access database. If I want to create a function in VB6 that adding data into my data base by typing the new data on textbox and click the button. Is it possible.
How do i adding new data to my database? Hope to getting help from here. Thanks you very much

This is my code.... any problem? Why cant work?

Private Sub Command1_Click()
Data1.Recordset.AddNew
Data1.Recordset.Field(1).Value = InputBox("code")
Data1.Recordset.Update
End Sub

Private Sub Command6_Click()
 Picture2.Cls

    Data1.Recordset.MoveFirst
    Do While Not Data1.Recordset.EOF
     Picture2.Print Data1.Recordset![code]
     Text5.Text = Text5.Text & " " & Data1.Recordset![code]

     'Text5.Text = Data1.Recordset![code]
     Data1.Recordset.MoveNext
    Loop
End Sub

Private Sub Form_Load()
Data1.DatabaseName = App.Path & "\menu1.mdb"
    Data1.RecordSource = "Table1"
    Data1.Refresh

    Text1.DataField = "Code"
End Sub

Edited 3 Years Ago by pyTony: fixed formating

Try this one...
First save your database and project on the same folder. 2nd create/add a module then put this in your module.

Option Explicit
Public db As Database

Sub Main
     Set db=OpenDatabase(App.Path & "\menu1.mdb")
      Form1.Show
End Sub

3rd Go to Project menu select Project Properties. On the Startup object select the Sub Main

In your Form1 where you add a data in you db put this code

Private Sub Form_Load()
     Set Data1.Recordset=db.Openrecordset("Select * from [[I]name of the table[/I]]")
End Sub

Private Sub AddBtn_Click()
     With Data1.Recordset
          .AddNew
          ![I]fieldname1[/I]=Text1.Text
          ![I]fieldname2[/I]=Text2.Text
          ![I]fieldname3[/I]=Text3.Text
          .Update
    End With
End Sub

Hi nuin,

After adding Data To the Table, u will have To Refresh, then only newly added data will show up.
Check this :

Data1.Recordset.AddNew
Data1.Recordset.Field(1).Value = InputBox("code")
Data1.Recordset.Update
[B]Data1.Recordset.Refresh[/B]

Regards
Veena

Thanks you i got it le..
now my database problem all solve...
Thank you everyone...
But Now turn to the Timer part problem...x_x

This article has been dead for over six months. Start a new discussion instead.