Solved

Easy Database Access

Posted on 2003-11-10
4
166 Views
Last Modified: 2010-05-03
I am trying to send data to access, as well as edit and delete it.

I used the Visual Data Manager and created a DB called yob with two fields named "Name" and "Date".

I added the data control and connected to my form with two text boxes: txtName and txtDate.

I connected to the database with the data control and set the data Field for txtName and txtDate correctly.

I added command buttons for Add, Delete, Change and Search.

******THE QUESTION*******

Here is the code for the add button

Private Sub cmdAdd_Click()
 Form1.Data1.Recordset.AddNew
End Sub

I get this error:

Error - "Action was cancelled by an associated object" Error - 3426

- How can I Fix this error? I am simply looking for a way to add new record to the database.

- Also, how can I code the delete and edit buttons?


thanks
0
Comment
Question by:greg222
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
Sairam_S earned 100 total points
ID: 9720911
0
 

Author Comment

by:greg222
ID: 9723781
i tried that. I can only add two records, then the last record is overwritten
0
 

Author Comment

by:greg222
ID: 9723912
It will not work. Here is the code so far:



Private Sub cmdAdd_Click()

 If Not (datMain.Recordset.BOF Or datMain.Recordset.EOF) Then
          datMain.Recordset.MoveLast
          datMain.Recordset.MoveNext
        End If


If datMain.Recordset.EOF Or datMain.Recordset.BOF Then
               
              MsgBox "true" 'debug
             
              Dim strBuffer As String, strBuff2 As String

              ' Save what was typed into the text box into memory
              strBuffer = txtInvNum.Text
              strBuff2 = txtDes.Text
             
              ' Restore text box value to the original record contents
              ' in this case, that is NULL
              datMain.UpdateControls

              ' Add a new blank record
              datMain.Recordset.AddNew

              ' Restore what has been typed from memory to text box
              txtInvNum.Text = strBuffer
              txtDes.Text = strBuff2
             
              ' Save the current record we are on and Add a new blank
              ' record
              datMain.Recordset.AddNew
              'datMain.Recordset.MoveLast
             
              txtInvNum.Text = ""
              txtDes.Text = ""
              datMain.Recordset.AddNew

Else
              MsgBox "else" ' debug
             
              'datMain.Recordset.MoveLast
              datMain.Recordset.AddNew
              txtInvNum.Text = ""
              txtDes.Text = ""
End If

End Sub


I just want to add new records, but this is not working.
0
 
LVL 5

Assisted Solution

by:fantasy1001
fantasy1001 earned 100 total points
ID: 9728675
VB comes with a standard solution for this.
You can access it via Project->Add Form, then choose "VB Data Form Wizard", follow all the step and VB will generate a easy solution for you. Thanks

~ fantasy ~
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

860 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