Link to home
Start Free TrialLog in
Avatar of peter_chong
peter_chong

asked on

Add record by ADO in VB6

I would like to learn ADO. Therefore, I have created some textboxes to bound with the Access database. My main purpose here is to add record via a form to the db 's table. I have created
a new database with a new design table,e.g: customers, but it has empty record as an initial stage.

I found that I can't add any record via vb form, since whatever character that I typed in the textboxes become blank again,when I navigate from one textbox to another textbox.

If I add a record into the table via manual insert to Access, then the vb textboxes have no error,
since it show record.

If I have an empty record table, then the textboxes cannot take any string.

How to resolve this problem via code or configuration???

Please help.

Regards,
Peter
 
Private Sub cmdSubmit_Click()
    adoCus.Recordset.AddNew
    adoCus.Recordset.Update
End Sub

Open in new window

Avatar of advfinance
advfinance
Flag of United Kingdom of Great Britain and Northern Ireland image

This is the way I do it:-

this is where " db " is your connection to the database

Dim adoCus as new adodb.recordset
adoCus.open "TableName", db,3,3
adoCus.addnew
adoCus!FieldName1=trim(MyForm.textBox1.text)
adoCus!FieldName2=trim(MyForm.textBox2.text)
adoCus!FieldName3=trim(MyForm.textBox3.text)
adoCus.update
adoCus.close
set adoCus=nothing

(This is typed direct on to the Experts web site - so no syntax checked)

Further info here:-
http://msdn.microsoft.com/en-us/library/bb407304(VS.80).aspx

Mike.


Avatar of peter_chong
peter_chong

ASKER

this is where " db " is your connection to the database?
Is this the Path of the db?
Please give some example.
TQ.
Below is my code:

Private Sub cmdSubmit_Click()

Dim adoFA As New adodb.Recordset

Dim counter As Integer

Dim strConnection As String

strConnection = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\learn_vb\db\abc.mdb;Persist Security Info=False"

adoFA.Open tblAsset, strConnection, adOpenDynamic, adLockPessimistic


adoFA.AddNew
'adoFA!Id = counter+1
adoFA!Name = Trim(frmAsset.txtName.Text)
adoFA.Update
adoFA.Close
Set adoFA = Nothing
End Sub

I have convert all data control,e.g text box to normal, since "blank" is still exist.
Any amendment to make the database manipulation  work.
Also help me how to implement counter logic in the primary key, Id in this case.
Points will be reward.

Thanks

Rgds,
Peter

Try adding adocus.recordset.new to form load()
 
lundca:
Not work! No method found.
ASKER CERTIFIED SOLUTION
Avatar of lundca
lundca

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial