Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Easy Database Access

Posted on 2003-11-10
4
Medium Priority
?
174 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 400 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 400 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 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…
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…
Suggested Courses

876 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