G
Guest
Hi
Please guide me on ADO : I have created small DB for entering Invoices
with its details, I use unbound form to save the invoices details to table,
“tInvoices†. On form I have button Save , on clicking this my details are
saving to table properly with code as :
Private Sub cmdSave_Click()
Dim conn As ADODB.Connection : Dim rst As ADODB.Recordset
Dim strConn As String
strConn = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & CurrentProject.Path & _
"\ProjectTransport.mdb
Set rst = New ADODB.Recordset
With rst
.Open "tInvoices", strConn, adOpenKeyset, adLockOptimistic
.AddNew
.Fields("InvDate").Value = InvDate : .Fields("InvoiceNo").Value =
InvoiceNo
.Fields("SubInvoice").Value = SubInvoice: .Fields("CoName").Value =
CoName
And closing the records set.
I ‘ve InvoiceNo and SubInvoice as Primary Key InvoiceNo Duplicate OK. I
wrote after update of subInvoice this code to bring data on the form
control if it is there:
Private Sub SubInvoice_AfterUpdate()
Dim conn As ADODB.Connectionim rst As ADODB.Recordset
Dim strConn As String
strConn = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & CurrentProject.Path & _
"\ProjectTransport.mdb"
Set rst = New ADODB.Recordset
With rst
.Open "SELECT * FROM tInvoices WHERE InvoiceNo = " & Me!InvoiceNo &
" and SubInvoice= " & Me!SubInvoice & " ", strConn, adOpenKeyset,
adLockOptimistic
InvDate = .Fields("InvDate").Value: InvoiceNo =
..Fields("InvoiceNo").Value
SubInvoice = .Fields("SubInvoice").Value: CoName =
..Fields("CoName").Value
After changing the company name, I want to save the record with same InvNo
and same subNo with save button , I m getting Run time error telling
“Duplicate value in index.. Please solve my problem and check my code, is it
correct?
Thanking you in advance,
PS I want to know any site which will help me to get idea about ADO.
Wahab
Please guide me on ADO : I have created small DB for entering Invoices
with its details, I use unbound form to save the invoices details to table,
“tInvoices†. On form I have button Save , on clicking this my details are
saving to table properly with code as :
Private Sub cmdSave_Click()
Dim conn As ADODB.Connection : Dim rst As ADODB.Recordset
Dim strConn As String
strConn = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & CurrentProject.Path & _
"\ProjectTransport.mdb
Set rst = New ADODB.Recordset
With rst
.Open "tInvoices", strConn, adOpenKeyset, adLockOptimistic
.AddNew
.Fields("InvDate").Value = InvDate : .Fields("InvoiceNo").Value =
InvoiceNo
.Fields("SubInvoice").Value = SubInvoice: .Fields("CoName").Value =
CoName
And closing the records set.
I ‘ve InvoiceNo and SubInvoice as Primary Key InvoiceNo Duplicate OK. I
wrote after update of subInvoice this code to bring data on the form
control if it is there:
Private Sub SubInvoice_AfterUpdate()
Dim conn As ADODB.Connectionim rst As ADODB.Recordset
Dim strConn As String
strConn = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & CurrentProject.Path & _
"\ProjectTransport.mdb"
Set rst = New ADODB.Recordset
With rst
.Open "SELECT * FROM tInvoices WHERE InvoiceNo = " & Me!InvoiceNo &
" and SubInvoice= " & Me!SubInvoice & " ", strConn, adOpenKeyset,
adLockOptimistic
InvDate = .Fields("InvDate").Value: InvoiceNo =
..Fields("InvoiceNo").Value
SubInvoice = .Fields("SubInvoice").Value: CoName =
..Fields("CoName").Value
After changing the company name, I want to save the record with same InvNo
and same subNo with save button , I m getting Run time error telling
“Duplicate value in index.. Please solve my problem and check my code, is it
correct?
Thanking you in advance,
PS I want to know any site which will help me to get idea about ADO.
Wahab