greg222
asked on
Easy Database Access
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.AddN ew
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
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.AddN
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.MoveLas t
txtInvNum.Text = ""
txtDes.Text = ""
datMain.Recordset.AddNew
Else
MsgBox "else" ' debug
'datMain.Recordset.MoveLas t
datMain.Recordset.AddNew
txtInvNum.Text = ""
txtDes.Text = ""
End If
End Sub
I just want to add new records, but this is not working.
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.MoveLas
txtInvNum.Text = ""
txtDes.Text = ""
datMain.Recordset.AddNew
Else
MsgBox "else" ' debug
'datMain.Recordset.MoveLas
datMain.Recordset.AddNew
txtInvNum.Text = ""
txtDes.Text = ""
End If
End Sub
I just want to add new records, but this is not working.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER