RstDup problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • clloyd
    New Member
    • Mar 2008
    • 91

    RstDup problem

    I am using the follow code to repeat a field value in a new record so it does not have to be automatically entered.

    Code:
    Public Sub cmdRecordAdd_Click()
    
        DoCmd.GoToRecord , , acNewRec
         
        Dim RstDup As Recordset
    
        ' Gets duplicate copy of current recordset to use
        Set RstDup = Me.RecordsetClone
         
        ' Moves to the last record  in the set , being the last entered to get the data for the new form
        RstDup.MoveLast
         
        ' Sets the information from fields from last record into current record, put each field you want duplicated in this list
    
        Me![ClientNo] = RstDup![ClientNo]
         
        'Closes the cloned recordset
        RstDup.Close
        Set RstDup = Nothing
    
    End Sub
    On some of my databases I get a type mismatch error and the only diffence I can find is in the databases where I get this error I notice they are set with a GUID indesing and did read something about DAO ADO databases. I am new and do not know what that means or how some of my databases are set up with this and some are not. Does anyone have any ideas how I can get around this problem.
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    It may be conveniently done setting control DefaultValue property after control update.
    Repeating values for a field in several records

    Regards,
    Fish

    Comment

    • Stewart Ross
      Recognized Expert Moderator Specialist
      • Feb 2008
      • 2545

      #3
      Hi. You may well have to qualify the RstDup recordset definition as a DAO recordset. DAO and ADO recordsets use slightly different methods, and type mismatches arise when ADO is taken to be the default instead of the Access-specific DAO type (which is the type you are actually using here).

      Change the DIM to
      [code=vb]Dim RstDup as DAO.Recordset[/code]
      You should also check that you have a reference to the DAO code library. From the VB Editor select Tools, References and make sure that there is a tick against the Microsoft Data Access Objects 3.6 Object Library (or whatever the latest version is on your system).

      -Stewart

      ps Setting the default value as Fish has indicated is a far, far simpler approach!

      Comment

      • clloyd
        New Member
        • Mar 2008
        • 91

        #4
        Thank you so much I changed this setting as you requested and it works perfectly now.

        Comment

        Working...