• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1396
  • Last Modified:

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

0
peter_chong
Asked:
peter_chong
  • 3
  • 2
1 Solution
 
advfinanceCommented:
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.


0
 
peter_chongAuthor Commented:
this is where " db " is your connection to the database?
Is this the Path of the db?
Please give some example.
TQ.
0
 
peter_chongAuthor Commented:
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

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
lundcaCommented:
Try adding adocus.recordset.new to form load()
 
0
 
peter_chongAuthor Commented:
lundca:
Not work! No method found.
0
 
lundcaCommented:
Did you use the ADODC control to set up your ADODC connection string? If so, I'm assuming that you renamed it adocus from ADODC1
Here's a link:
http://msdn.microsoft.com/en-us/library/aa227291.aspx
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now