Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

adodb and data grid question

Posted on 2004-10-25
4
Medium Priority
?
284 Views
Last Modified: 2010-05-02
I am having a problem figuring datagrids and adodb oout.
I ahve a data grid that is connected to the database using an adodb
What I need to know is how to make the datagrid update the databse.
I notice that when I teab out of the grid it updates the database. Is there way of calling this from a button that is easy.
When I try and do adodb1.recordset.update i get cannot insert empty row errors.

thanks in advance.

Shayne  
0
Comment
Question by:shayne23d
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:shayne23d
ID: 12403951
here is what I have in code.

what am I missing


Private rs As ADODB.Recordset
Private Const UPDATE_CANCELLED As Long = -2147217842
Private Const ERRORS_OCCURED As Long = -2147217887



Private Sub Adodc1_RecordsetChangeComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
   If adStatus = adStatusOK Then
      cmdDelete.Enabled = True
   End If
End Sub

Private Sub Adodc1_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
   Select Case adReason
   Case adRsnUndoAddNew, adRsnUndoUpdate, adRsnFirstChange
      'Do nothing
   Case Else

     
   
  End Select
 
     
   
End Sub

Private Sub cmdAdd_Click()
   rs.r
End Sub

Private Sub cmdCancel_Click()


      rs.Cancel
     
     

   
   
   
   

End Sub

Private Sub cmdDelete_Click()
   If MsgBox("Are you sure you want to delete this record? ", vbQuestion + vbYesNo, "Delete REcord") = vbYes Then
      'rs.CancelUpdate
      'rs.Bookmark = rs.Bookmark
      rs.Delete
      'rs.MoveFirst
      'Adodc1.Refresh
     
   End If
     
   
End Sub

Private Sub MoveToRecord(intDirection As Integer)
   On Error GoTo MoveToRecord_Err
   
   Select Case intDirection
      Case adRsnMoveFirst
         rs.MoveFirst
      Case adRsnMovePrevious
         rs.MovePrevious
         If rs.BOF Then
            rs.MovePrevious
         End If
      Case adRsnMoveNext
         rs.MoveNext
         If rs.EOF Then
            rs.MovePrevious
         End If
      Case adRsnMoveLast
         rs.MoveLast
      Case adRsnAddNew
         rs.AddNew
         Adodc1.Refresh
         
         'cmdDelete.Enabled = False
      End Select
     
MoveToRecord_exit:
      Exit Sub
MoveToRecord_Err:
   Select Case Err.Number
      Case UPDATE_CANCELLED, ERRORS_OCCURED
         ' Do Nothing
      Case Else
         'Err.Raise Err.Number, Err.Source, Err.Description
      End Select
      Resume MoveToRecord_exit
     

End Sub


Private Sub cmdFindRecord_Click()
   Dim strSearch As String
   Dim strSQL As String
   
   
   
   If (Trim$(txtPLMS.Text) = "") Then 'And Trim$(txtEDMS.Text) = "") Then
       MsgBox "You must enter a PLMS#  to perform a search ", vbOKCancel
       txtPLMS.SetFocus
         Else:

     
     
         strSearch = (Trim$(txtPLMS.Text))
         strSQL = "Select * from kaiserLetters where plms_number = " & strSearch
         Adodc1.RecordSource = strSQL
         Adodc1.CommandType = adCmdText
         Adodc1.Refresh
       
      End If
         
     
End Sub

Private Sub cmdRefresh_Click()
Adodc1.Refresh

End Sub



Private Sub DataGrid1_LostFocus()

   rs.Update
   
   
End Sub

Private Sub Form_Load()
   Set rs = Adodc1.Recordset
   
End Sub

0
 

Author Comment

by:shayne23d
ID: 12404422
ok quick change sorry.
I have the add working now the only part I am having a problem with is the delete.
it seems that whenI delete something I need to then hit the refresh button and it all works fine. but if I call adodc1.refresh in the delete command it does not work the same? I eventually hit a record that is marked for deletion and get an error.
Wha tam i missing there?

here is the current code


Private rs As ADODB.Recordset
Private Const UPDATE_CANCELLED As Long = -2147217842
Private Const ERRORS_OCCURED As Long = -2147217887



Private Sub Adodc1_RecordsetChangeComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
   If adStatus = adStatusOK Then
      cmdDelete.Enabled = True
   End If
End Sub

Private Sub Adodc1_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
   Select Case adReason
   Case adRsnUndoAddNew, adRsnUndoUpdate, adRsnFirstChange
      'Do nothing
   Case Else

     
   
  End Select
 
     
   
End Sub

Private Sub cmdAdd_Click()
   Adodc1.Recordset.Update
   Adodc1.refresh
   
   
End Sub

Private Sub cmdCancel_Click()


      rs.Cancel
     
End Sub

Private Sub cmdDelete_Click()
   If MsgBox("Are you sure you want to delete this record? ", vbQuestion + vbYesNo, "Delete REcord") = vbYes Then
     
      Adodc1.refresh
     
      rs.Delete
      Adodc1.refresh
     

   End If
     
   
End Sub




Private Sub cmdFindRecord_Click()
   Dim strSearch As String
   Dim strSQL As String
   
   
   
   If (Trim$(txtPLMS.Text) = "") Then 'And Trim$(txtEDMS.Text) = "") Then
       MsgBox "You must enter a PLMS#  to perform a search ", vbOKCancel
       txtPLMS.SetFocus
         Else:

     
     
         strSearch = (Trim$(txtPLMS.Text))
         strSQL = "Select * from kaiserLetters where plms_number = " & strSearch
         Adodc1.RecordSource = strSQL
         Adodc1.CommandType = adCmdText
         Adodc1.refresh
       
      End If
         
     
End Sub

Private Sub cmdRefresh_Click()
Adodc1.refresh

End Sub



Private Sub DataGrid1_LostFocus()

   rs.Update
   
   
End Sub

Private Sub Form_Load()
   Set rs = Adodc1.Recordset
   
End Sub

sorry for allthe switching around of code but the day is just like that

thanks in advance

shayne
0
 
LVL 3

Accepted Solution

by:
Noel_Castillo earned 1000 total points
ID: 12408959
why are you mixing adodc with adodb? the prob there is that you're havin two different recordset.
I assume that the datasource of the datagrid is the Adodc1. maybe you could use Adodc1.Recordset.Delete instead of rs.Delete.

0
 
LVL 3

Expert Comment

by:Noel_Castillo
ID: 12409008
Sorry. i'd just noticed that you referenced adodc1.recordset with rs. thats my mistake. but you could still try using  Adodc1.Recordset.Delete instead
0

Featured Post

Independent Software Vendors: 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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 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…
Suggested Courses

636 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