Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

AddNew to Dynaset in VB5

Posted on 1998-07-08
5
Medium Priority
?
382 Views
Last Modified: 2012-05-04
I'm trying to open a recordset as a dynaset using a select statement.  If the select does not find the record in the where clause than it does an AddNew to the recordset.  This works fine on the first open but the next attempt results in an error 3426 - This action was cancelled by an associated object.  Am I using the correct process?  Is there a better solution?  I also need to set the primary keys.  After AddNew, the user must enter data, then I need to user lastmodified to update the rec keys before updating.  Any and all help would be appreciated.  Thanks

'***  Here is the script that you requested ***'

Private Sub OpenPDate()
   
    On Error GoTo Requester_Err:
     
    Dim strparm         As String
    Dim myset           As Recordset
   
    Me.MousePointer = 11    

    strparm = _
        "SELECT project_recno, begin_date, select_site_date, lease_date, reg_date, " & _
            "developed_date, award_date, estimated_end_date, actual_end_date " & _
            "From project_dates " & _
            "WHERE (project_recno = " & Str(gs_project_rec) & " );"
   
    Set myset = MyDb.OpenRecordset(strparm, dbOpenDynaset)
    If myset.RecordCount > 0 Then
        Data11.RecordSource = strparm
        Data11.Refresh
    Else
        Call cmdAdd_Click
    End If
    myset.Close
   
    me.MousePointer = 0    ' Change mouse pointer to normal.
    Exit Sub
end sub
   

Private Sub cmdAdd_Click()
    On Error GoTo Requester_Err:
   
    Me.MousePointer = 11    ' hourglass

    Select Case SSTab1.Tab
       
        Case 2
       
            Data11.Recordset.AddNew
end sub
 
         
Private Sub Data11_Validate(Action As Integer, Save As Integer)
    On Error GoTo Requester_Err:
   
    Select Case Action
       
        Case vbDataActionAddNew
         
            If Data11.Recordset.Bookmarkable = True Then
                Data11.Recordset.Bookmark =                 Data11.Recordset.LastModified
            End If
end sub


'***  wait for user input ***

Private Sub cmdUpdate_Click()
    On Error GoTo Requester_Err
   
    Dim wvalue          As Variant
    Dim retval          As Variant
    Dim typeid          As Long
 
    Me.MousePointer = 11   'hourglass
 
    Select Case SSTab1.Tab
     
        Case 2
               
            Data11.Recordset.MoveLast
            If Data11.Recordset.Fields("project_recno") = 0 Or _
                IsNull(Data11.Recordset.Fields("project_recno"))                 Then
                Data11.Recordset.Fields("project_recno") =                 gs_project_rec
                Call CheckDates
                Data11.Recordset.Fields("date_updated") = Date
                Data11.Recordset.Update
            Else
                Data11.Recordset.Update
            End If
            Data11.Recordset.Bookmark =                          Data11.Recordset.LastModified
end if

Sorry this is so long; I got everything but problem.  Thanks in advance for your help.        
       



0
Comment
Question by:NJMet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Expert Comment

by:tomook
ID: 1465250
From your description, it appears you are doing the following steps:
1. Open a recordset with a specific WHERE clause, ex. "SELECT Field1 FROM Table1 WHERE Field1=1"
2. If no record found, add a record, ex.
 rs.AddNew
 rs.Field1=1
 rs.Update
3. Adding another record, ex.
 rs.AddNew
 rs.Field1 = 2
 rs.Update

If so, the WHERE clause in the original SELECT statement is your problem. You may need to change you logic to
1. (No change)
2. If no record found, add a record.
2a. Open a new recordset
3. Add a new record.
0
 
LVL 1

Expert Comment

by:shagnasty
ID: 1465251
Post the SQL statement you are using to open the recordset...
0
 
LVL 5

Expert Comment

by:yronnen
ID: 1465252
Are you using a Data control?
0
 

Author Comment

by:NJMet
ID: 1465253
Edited text of question
0
 
LVL 1

Accepted Solution

by:
shagnasty earned 100 total points
ID: 1465254
You need to add the following lines:

---Snip---
Set myset = MyDb.OpenRecordset(strparm, dbOpenDynaset)

myset.movelast
myset.movefirst  'Record count need to load the whole recordset to work!

If myset.RecordCount > 0 Then
---Snip---


0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question