Hey all,

I have a small issue. If i go into my form (has a DG and ado connection) and add a record (uses button) - it sets up some defaults. If i change the record, the changes arent saved when i close and go back in. But if i then change the record after i go back in the record saves.

Any ideas whats wrong? Code attached

VB Code:
  1. Option Explicit
  2. Dim bInsertRec As Boolean
  3. 'Add currency combo in at bottom
  4. 'Tax rate
  5.  
  6.  
  7.  
  8. Private Sub CbCurrency_Change()
  9.  
  10. Call CbTransaction_Change
  11.  
  12. End Sub
  13.  
  14. Private Sub CbCurrency_Click()
  15.  
  16. Call CbTransaction_Change
  17.  
  18. End Sub
  19.  
  20. Private Sub CbTaxRate_Change()
  21.  
  22. Call CbTransaction_Change
  23.  
  24. End Sub
  25.  
  26. Private Sub CbTaxRate_Click()
  27.  
  28. Call CbTransaction_Change
  29.  
  30. End Sub
  31.  
  32. Private Sub CbTransaction_Change()
  33.  
  34. If Len(CbTransaction.Text) > 0 And Len(CbCurrency.Text) > 0 And Len(CbTaxRate.Text) > 0 Then
  35.     CmdAddTrans.Enabled = True
  36. Else
  37.     CmdAddTrans.Enabled = False
  38. End If
  39.  
  40. End Sub
  41.  
  42. Private Sub CbTransaction_Click()
  43.  
  44. Call CbTransaction_Change
  45.  
  46. End Sub
  47.  
  48. Private Sub CmdAddTrans_Click()
  49.  
  50. 'insert routine
  51.  
  52. StrTaxRate = CbTaxRate
  53.  
  54. If Adodc.RecordSet.RecordCount > 0 Then
  55.  
  56.     Adodc.RecordSet.MoveLast
  57.    
  58.     If IsNull(Adodc.RecordSet.Fields("Total Premium").Value) = True Or Len(Adodc.RecordSet.Fields("Total Premium").Value) = 0 Or Adodc.RecordSet.Fields("Total Premium").Value = 0 Then
  59.         StrMsg = "Premium on last entry not complete.  Do you wish to remove this entry?"
  60.         Style = vbExclamation + vbYesNo
  61.         StrTitle = App.FileDescription & " - User Error"
  62.         IntResponse = MsgBox(StrMsg, Style, StrTitle)
  63.         If IntResponse = vbYes Then
  64.             Adodc.RecordSet.Delete (adAffectCurrent)
  65.             Exit Sub
  66.         Else
  67.             Exit Sub
  68.         End If
  69.     End If
  70.    
  71.     If IsNull(Adodc.RecordSet.Fields("Bordereau Month").Value) = True Then
  72.         StrMsg = "Bordereau Month on last entry not complete.  Do you wish to remove this entry?"
  73.         Style = vbExclamation + vbYesNo
  74.         StrTitle = App.FileDescription & " - User Error"
  75.         IntResponse = MsgBox(StrMsg, Style, StrTitle)
  76.         If IntResponse = vbYes Then
  77.             Adodc.RecordSet.Delete (adAffectCurrent)
  78.             Exit Sub
  79.         Else
  80.             Exit Sub
  81.         End If
  82.     End If
  83.  
  84.     If IsNull(Adodc.RecordSet.Fields("Bordereau Year").Value) = True Then
  85.         StrMsg = "Bordereau Year on last entry not complete.  Do you wish to remove this entry?"
  86.         Style = vbExclamation + vbYesNo
  87.         StrTitle = App.FileDescription & " - User Error"
  88.         IntResponse = MsgBox(StrMsg, Style, StrTitle)
  89.         If IntResponse = vbYes Then
  90.             Adodc.RecordSet.Delete (adAffectCurrent)
  91.             Exit Sub
  92.         Else
  93.             Exit Sub
  94.         End If
  95.     End If
  96.    
  97.     If Adodc.RecordSet.Fields("Bordereau Month").Value < 1 Or Adodc.RecordSet.Fields("Bordereau Month").Value > 12 Then
  98.         StrMsg = "Bordereau Month on last entry not valid (must be number between 1-12)." & vbCr & _
  99.                 "Do you wish to remove this entry?"
  100.         Style = vbExclamation + vbYesNo
  101.         StrTitle = App.FileDescription & " - User Error"
  102.         IntResponse = MsgBox(StrMsg, Style, StrTitle)
  103.         If IntResponse = vbYes Then
  104.             Adodc.RecordSet.Delete (adAffectCurrent)
  105.             Exit Sub
  106.         Else
  107.             Exit Sub
  108.         End If
  109.     End If
  110.    
  111.     If Adodc.RecordSet.Fields("Bordereau Year").Value > DatePart("yyyy", Now) Then
  112.         StrMsg = "Bordereau Month on last entry not valid (cannot be in the future)." & vbCr & _
  113.                 "Do you wish to remove this entry?"
  114.         Style = vbExclamation + vbYesNo
  115.         StrTitle = App.FileDescription & " - User Error"
  116.         IntResponse = MsgBox(StrMsg, Style, StrTitle)
  117.         If IntResponse = vbYes Then
  118.             Adodc.RecordSet.Delete (adAffectCurrent)
  119.             Exit Sub
  120.         Else
  121.             Exit Sub
  122.         End If
  123.     End If
  124.    
  125.     If Adodc.RecordSet.Fields("Bordereau Year").Value < DatePart("yyyy", Now) - 1 Then
  126.         StrMsg = "Bordereau Month on last entry not valid (cannot be further then a year in the past)." & vbCr & _
  127.                 "Do you wish to remove this entry?"
  128.         Style = vbExclamation + vbYesNo
  129.         StrTitle = App.FileDescription & " - User Error"
  130.         IntResponse = MsgBox(StrMsg, Style, StrTitle)
  131.         If IntResponse = vbYes Then
  132.             Adodc.RecordSet.Delete (adAffectCurrent)
  133.             Exit Sub
  134.         Else
  135.             Exit Sub
  136.         End If
  137.     End If
  138.        
  139. End If
  140.  
  141. DGAgentAccounts.Refresh
  142.  
  143. With Adodc.RecordSet
  144.     .AddNew
  145.     .Fields("Agent number").Value = StrAgentNumber
  146.     .Fields("Transaction date").Value = Now
  147.     .Fields("Transaction Type").Value = CbTransaction.Text
  148.     .Fields("Total Premium").Value = 0
  149.     .Fields("Tax Amount").Value = 0
  150.     .Fields("Currency").Value = CbCurrency.Text
  151.     .Fields("User Name").Value = StrUserName
  152.     .Update
  153. End With
  154. bInsertRec = True
  155.  
  156. DGAgentAccounts.AllowUpdate = True
  157. DGAgentAccounts.SetFocus
  158. Adodc.RecordSet.MoveLast
  159.  
  160. End Sub
  161.  
  162.  
  163. Private Sub DataGrid1_AfterUpdate()
  164.  
  165. 'call validate?
  166. End Sub
  167.  
  168.  
  169.  
  170. Private Sub DataGrid1_Error(ByVal DataError As Integer, Response As Integer)
  171.  
  172. 'err handle
  173.  
  174. End Sub
  175.  
  176. Private Sub DGAgentAccounts_AfterColUpdate(ByVal ColIndex As Integer)
  177. Adodc.RecordSet.Fields("Tax Amount").Value = Round(Adodc.RecordSet.Fields("Total Premium").Value - (Adodc.RecordSet.Fields("Total Premium").Value / (1 + StrTaxRate)), 2)
  178. End Sub
  179.  
  180. Private Sub DGAgentAccounts_BeforeInsert(Cancel As Integer)
  181. 'Valid
  182. End Sub
  183.  
  184.  
  185.  
  186. Private Sub DGAgentAccounts_KeyDown(KeyCode As Integer, Shift As Integer)
  187.  
  188. If Shift = 1 Then
  189.     If KeyCode = 9 Or KeyCode = 16 Then
  190.         Exit Sub
  191.     Else
  192.         KeyCode = 0
  193.         Beep
  194.     End If
  195. End If
  196.  
  197. Select Case KeyCode
  198.     Case 8, 9, 13, 37 To 40, 46, 48 To 57, 96 To 105, 189
  199.         Exit Sub
  200.     Case 109, 189
  201.         If InStr(DGAgentAccounts.Text, "-") > 0 Then
  202.             KeyCode = 0
  203.             Beep
  204.         End If
  205.     Case 110, 190
  206.         If InStr(DGAgentAccounts.Text, ".") > 0 Then
  207.             KeyCode = 0
  208.             Beep
  209.         End If
  210.     Case Else
  211.         KeyCode = 0
  212.         Beep
  213. End Select
  214.  
  215. end Sub
  216.  
  217.  
  218. Private Sub Form_Load()
  219.  
  220. bInsertRec = False
  221.  
  222. Set DGAgentAccounts.DataSource = Nothing
  223. Adodc.ConnectionString = PLCYConnectionString
  224. Adodc.RecordSource = "Select * from [agent accounts] where [Agent number] ='" & StrAgentNumber & "' order by [transaction date]"
  225. Adodc.Refresh
  226.  
  227.  
  228.  
  229.  
  230.  
  231. Set DGAgentAccounts.DataSource = Adodc
  232. DGAgentAccounts.Columns(0).Visible = False 'Transaction ID
  233. DGAgentAccounts.Columns(1).Visible = False 'Agent number
  234. DGAgentAccounts.Columns(2).Locked = True 'Transaction Date
  235. DGAgentAccounts.Columns(3).Locked = True 'Transaction Type
  236. DGAgentAccounts.Columns(5).Locked = True 'Tax amount
  237. DGAgentAccounts.Columns(6).Locked = True 'Currency
  238. DGAgentAccounts.Columns(9).Locked = True 'Username
  239.  
  240. DGAgentAccounts.AllowUpdate = True
  241. 'set fields up which are locked etc
  242. 'reference field by ado.rs.field("") etc easy 2 debug!
  243. End Sub
  244.  
  245. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  246.  
  247. 'Call validate
  248.  
  249. 'FrmAgentAccounts.Hide
  250. frmAgentsDetails.Show
  251.      
  252.  
  253. End Sub


Any help really appreciated!

Dan