Solved

Easy Database Access

Posted on 2003-11-10
4
163 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
Comment Utility
0
 

Author Comment

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

Author Comment

by:greg222
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now