|
-
Mar 22nd, 2006, 06:05 AM
#1
Thread Starter
Lively Member
[RESOLVED] eveything in my project has decided to break, help with this function please
i *think* i might have narrowed down at least part of the cause of my program behaving so oddly.
this function is supposed to add a customer to both the database and my array "Control.CustomerList.Customer()"
VB Code:
Public Function AddNewToDB(templateCust As clsCustomer, Optional ByVal SaveDatabase As String = "none") As Boolean
' add new record to the db
' open the db
Dim DB As Database
' check if a parameter was passed to it
If SaveDatabase = "none" Then
' load default
Set DB = OpenDatabase(App.Path & "\database.mdb")
Else
' load other
Set DB = OpenDatabase(SaveDatabase)
End If
Dim RS As Recordset
Set RS = DB.OpenRecordset("tunings")
If Not (RS.RecordCount = CustomerList.NumberOfCustomers) Then
AddNewToDB = False ' <---------------- HERE
Exit Function
End If
RS.MoveLast
RS.AddNew
Dim myTempCust As clsCustomer
Set myTempCust = Control.CustomerList.AddCustomer
Control.CustomerList.DuplicateCust myTempCust.ID, templateCust
Control.CustomerList.getCustomer(Control.CustomerList.NumberOfCustomers - 1).ID = RS!ID
RS.Edit
RS!Salutation = templateCust.Salutation
RS!FirstName = templateCust.FirstName
RS!MiddleInitials = templateCust.MiddleInitials
RS!LastName = templateCust.LastName
RS!CompanyName = templateCust.CompanyName
RS!Address1 = templateCust.Address1
RS!Address2 = templateCust.Address2
RS!Address3 = templateCust.Address3
RS!Postcode = templateCust.Postcode
RS!Areacode = templateCust.Areacode
RS!PhoneNumber = templateCust.PhoneNumber
RS!Comments = templateCust.Comments
RS!TuningA = templateCust.TuningA
RS!TuningB = templateCust.TuningB
RS!TuningC = templateCust.TuningC
RS!TuningD = templateCust.TuningD
RS!TuningsPerYear = templateCust.TuningsPerYear
RS!TuningDate = templateCust.TuningDate
RS!Options = templateCust.CodeOptions
RS!MapX = templateCust.MapX
RS!MapY = templateCust.MapY
RS.Update
AddNewToDB = True
' clean up
RS.Close
DB.Close
Set RS = Nothing
Set DB = Nothing
End Function
but, i have realised that if i start the program afresh, and run this twice by adding 2 customers, the first time it works great, but the second time it breaks at an error trapping point that i marked with [ '<------- Here ]
so i am assuming it either doesnt increment customerlist.size, or the record is not properly added to the database.
now i have just been figuring out this database stuff as i go along, so im hoping that that is where the error is. so could someone have a look over that to spot any errors please!
-
Mar 22nd, 2006, 06:19 AM
#2
Re: eveything in my project has decided to break, help with this function please
The RecordCount property of a recordset will only return correct results, if the last record has been the current record.
So you should do a RS.MoveLast before you consult the recordcount.
Be aware that a MoveLast will raise an error if the recordset is empty.
-
Mar 22nd, 2006, 06:28 AM
#3
Thread Starter
Lively Member
Re: eveything in my project has decided to break, help with this function please
even if i add in an rs.movelast just before, it still gives me the error
-
Mar 22nd, 2006, 06:32 AM
#4
Thread Starter
Lively Member
Re: eveything in my project has decided to break, help with this function please
i have a feeling there is no new record being created, or if it is created its not being saved.
-
Mar 22nd, 2006, 06:44 AM
#5
Re: eveything in my project has decided to break, help with this function please
try the rs.refresh method .see if it works!
__________________
________________0îîî___
___îîî0________(___)____
__(___)_________) _/_____
___\_ (_________(_/______
____\_)_________________
-
Mar 22nd, 2006, 06:48 AM
#6
Thread Starter
Lively Member
Re: eveything in my project has decided to break, help with this function please
no such method
im using DAO 3.6
-
Mar 22nd, 2006, 07:28 AM
#7
Thread Starter
Lively Member
Re: eveything in my project has decided to break, help with this function please
instead of adding a new one it seems to replace the previous one. why is this!?
-
Mar 22nd, 2006, 07:46 AM
#8
Thread Starter
Lively Member
Re: eveything in my project has decided to break, help with this function please
right, i figured it out myself, one of the things that was throwing me off was that it was adding the new records randomly in the middle of the recordset.
how bizare!
anyway, i can search fro the records and find em no probs.
-
Mar 22nd, 2006, 08:19 AM
#9
Re: [RESOLVED] eveything in my project has decided to break, help with this function please
Yes, the RS.Edit should not be there.
You should use either RS.AddNew (to add a record) or RS.Edit (to edit a record) but not both.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|