Solved

Easy Database Access

Posted on 2003-11-10
4
164 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 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…

920 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

13 Experts available now in Live!

Get 1:1 Help Now