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
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
ASKER
this is where " db " is your connection to the database?
Is this the Path of the db?
Please give some example.
TQ.
Is this the Path of the db?
Please give some example.
TQ.
ASKER
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.OL EDB.4.0;Da ta Source=C:\learn_vb\db\abc. mdb;Persis t 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
Private Sub cmdSubmit_Click()
Dim adoFA As New adodb.Recordset
Dim counter As Integer
Dim strConnection As String
strConnection = _
"Provider=Microsoft.Jet.OL
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()
ASKER
lundca:
Not work! No method found.
Not work! No method found.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(MyF
adoCus!FieldName2=trim(MyF
adoCus!FieldName3=trim(MyF
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.