Results 1 to 9 of 9

Thread: [RESOLVED] eveything in my project has decided to break, help with this function please

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    94

    Resolved [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:
    1. Public Function AddNewToDB(templateCust As clsCustomer, Optional ByVal SaveDatabase As String = "none") As Boolean
    2.  
    3.         ' add new record to the db
    4.         ' open the db
    5.     Dim DB As Database
    6.        
    7.         ' check if a parameter was passed to it
    8.     If SaveDatabase = "none" Then
    9.             ' load default
    10.         Set DB = OpenDatabase(App.Path & "\database.mdb")
    11.     Else
    12.             ' load other
    13.         Set DB = OpenDatabase(SaveDatabase)
    14.         End If
    15.    
    16.     Dim RS As Recordset
    17.     Set RS = DB.OpenRecordset("tunings")
    18.    
    19.     If Not (RS.RecordCount = CustomerList.NumberOfCustomers) Then
    20.         AddNewToDB = False    ' <----------------   HERE
    21.         Exit Function
    22.         End If
    23.    
    24.     RS.MoveLast
    25.     RS.AddNew
    26.    
    27.     Dim myTempCust As clsCustomer
    28.     Set myTempCust = Control.CustomerList.AddCustomer
    29.     Control.CustomerList.DuplicateCust myTempCust.ID, templateCust
    30.     Control.CustomerList.getCustomer(Control.CustomerList.NumberOfCustomers - 1).ID = RS!ID
    31.    
    32.     RS.Edit
    33.         RS!Salutation = templateCust.Salutation
    34.         RS!FirstName = templateCust.FirstName
    35.         RS!MiddleInitials = templateCust.MiddleInitials
    36.         RS!LastName = templateCust.LastName
    37.         RS!CompanyName = templateCust.CompanyName
    38.         RS!Address1 = templateCust.Address1
    39.         RS!Address2 = templateCust.Address2
    40.         RS!Address3 = templateCust.Address3
    41.         RS!Postcode = templateCust.Postcode
    42.         RS!Areacode = templateCust.Areacode
    43.         RS!PhoneNumber = templateCust.PhoneNumber
    44.         RS!Comments = templateCust.Comments
    45.         RS!TuningA = templateCust.TuningA
    46.         RS!TuningB = templateCust.TuningB
    47.         RS!TuningC = templateCust.TuningC
    48.         RS!TuningD = templateCust.TuningD
    49.         RS!TuningsPerYear = templateCust.TuningsPerYear
    50.         RS!TuningDate = templateCust.TuningDate
    51.         RS!Options = templateCust.CodeOptions
    52.         RS!MapX = templateCust.MapX
    53.         RS!MapY = templateCust.MapY
    54.         RS.Update
    55.    
    56.     AddNewToDB = True
    57.    
    58.      ' clean up
    59.     RS.Close
    60.     DB.Close
    61.     Set RS = Nothing
    62.     Set DB = Nothing
    63.  
    64. 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!

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    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.
    Frans

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    94

    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

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    94

    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.

  5. #5
    Frenzied Member litlewiki's Avatar
    Join Date
    Dec 2005
    Location
    Zeta Reticuli Distro:Ubuntu Fiesty
    Posts
    1,162

    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________(___)____
    __(___)_________) _/_____
    ___\_ (_________(_/______
    ____\_)_________________

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    94

    Re: eveything in my project has decided to break, help with this function please

    no such method

    im using DAO 3.6

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    94

    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!?

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    94

    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.

  9. #9
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    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.
    Frans

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width