Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unbound Form Using a Disconnected Recordset

Status
Not open for further replies.

Adams

Technical User
Mar 10, 2001
44
0
0
US
I have created an unbound form that is erroring out when I try to save the current record. Do I need to define the type of data?

Sub SaveCurrentRecord()

'save the values in the controls on the form to the current record in the local disconnected recordset

If Not rsCustomer.BOF And Not rsCustomer.EOF Then
rsCustomer!Customer = Me.Customer
rsCustomer!TktCnt = Me.TktCnt
rsCustomer!Refund = Me.Refund
rsCustomer!NetSales = Me.NetSales
rsCustomer!AirComm = Me.AirComm
rsCustomer!CarComm = Me.CarComm
rsCustomer!HtlComm = Me.HtlComm
rsCustomer!RailSales = Me.RailSales
rsCustomer!RailComm = Me.RailComm
rsCustomer!SFCnt = Me.SFCnt
rsCustomer!SF = Me.SF
rsCustomer!SFComm = Me.SFComm
rsCustomer!Period = Me.Period
End If

End Sub

I am very much a rookie, would you explain the difference in Bound and Unbound and why unbound is used. Where is the unbound data stored until it is saved to the recordset?
 
Help us out.
What is the Error message?
Where does it break?

Probably:
If Not rsCustomer.BOF And Not rsCustomer.EOF Then
rsCustomer.AddNew
rsCustomer!Customer = Me.Customer
rsCustomer!TktCnt = Me.TktCnt
rsCustomer!Refund = Me.Refund
rsCustomer!NetSales = Me.NetSales
rsCustomer!AirComm = Me.AirComm
rsCustomer!CarComm = Me.CarComm
rsCustomer!HtlComm = Me.HtlComm
rsCustomer!RailSales = Me.RailSales
rsCustomer!RailComm = Me.RailComm
rsCustomer!SFCnt = Me.SFCnt
rsCustomer!SF = Me.SF
rsCustomer!SFComm = Me.SFComm
rsCustomer!Period = Me.Period
rsCustomer.update
End If
 
Could be
rsCustomer.Addnew or rsCustomer.edit
Depends which
 
Did you declare your recordset? Your code snippet doesn't show that.

You are going to need to do something like this:

Dim dbs As Database
Dim rsCustomer As Recordset

Set dbs = CurrentDB

Set rsCustomer = dbs.OpenRecordset("yourTable", dbOpenDynaset)
rsCustomer.AddNew
rsCustomer!Customer = Me.Customer
rsCustomer!TktCnt = Me.TktCnt
rsCustomer!Refund = Me.Refund
rsCustomer!NetSales = Me.NetSales
rsCustomer!AirComm = Me.AirComm
rsCustomer!CarComm = Me.CarComm
rsCustomer!HtlComm = Me.HtlComm
rsCustomer!RailSales = Me.RailSales
rsCustomer!RailComm = Me.RailComm
rsCustomer!SFCnt = Me.SFCnt
rsCustomer!SF = Me.SF
rsCustomer!SFComm = Me.SFComm
rsCustomer!Period = Me.Period
rsCustomer.Update

This will do a straight insert into yourTable using the values on the form. I am not sure if that is exactly what you want.

Things to keep in mind are that if you try to insert a record that violates any primary key field(s) values you will get an error, you would need to write code to prevent that.

Also, look in Access Help under Recordset, and look at the available methods (Edit, AddNew, Delete), and the rules on how to use them.
 
Run-Time Error
Multiple-step operation errors. Check each status value.
It is stopping on this line:
rsCustomer!TktCnt = Me.TktCnt

In the table the Data Type is Number and Field Size is Double.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top