Results 1 to 28 of 28

Thread: Sql Help - Needed Bad!!!!

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679

    Sql Help - Needed Bad!!!!

    I thought that I had a grip on this project, but I am not too sure now...

    This one form I created was supposed to show me data from an Access query by way of a Recordset...what happens though is that it shows the data but will not for the life of me move to the next record...

    I have attempted to attach a .zip file of a scaled down project with the form in question (frmCB.Form)

    If I am successful in attaching this (which I have not yet!), then you will need to make one adjustment...I attached the Access database, that will need to be placed on a seperate drive other than the floppy, it does not seem to work well otherwise...

    Also, when you get to the Login screen, type ' b452345 '...thank you..

    If the attachment does not work, would someone allow me to email them the project?

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    This attachment business is for the birds!!!!

    the zip file I have is only 67,000 bytes...and I am supposed to be able to send up to 105, 360 bytes!!!

    This is ridiculous!

    Anywho...

    If someone can assist me with this I would be very grateful!

  3. #3
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    just post the part of the code that your having the problem with.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    Ok here is what I have:

    VB Code:
    1. Private Sub chkCB_Click()
    2.                  'the code below I believe is where the problem lies
    3.          
    4. Private Sub cmdNextRec_Click()
    5. Const Formclose As Long = 3021
    6. On Error GoTo ErrorMsg
    7.  
    8. Dim msgbtn As Integer, strSelect As String, msgbtn2 As Integer
    9. Set rs = New Recordset
    10.  
    11. strSelect = "SELECT * FROM qryCompletedRef WHERE CallBackShift = '" & txtSalesShift.Text & "'"
    12. rs.Open strSelect, MyDataEnvironment.MyConnection, adOpenDynamic, adLockOptimistic
    13.  
    14. If txtSaleRep.Text = "" Then
    15. MsgBox "Please enter your name in the appropriate box before continuing!", vbCritical, "Your Name?"
    16. txtSaleRep.SetFocus
    17. Exit Sub
    18. Else
    19. If lstAppGen.Text = "" Then
    20. MsgBox "Please select if an application was generated!", vbCritical, "Application Generated?"
    21. lstAppGen.SetFocus
    22. Exit Sub
    23. Else
    24. chkCB.Value = 0
    25. rs.Fields("AgentCmpltd") = txtSaleRep.Text
    26. rs.Fields("CmpltdDate") = txtDateCmpltd.Text
    27. rs.Fields("AppGen") = lstAppGen.Text
    28. txtSlsRefNot.Text = rs.RecordCount
    29. txtSlsRefNot.Text = rs.RecordCount - 1
    30.    'when I click on this command button it changes the record count
    31.   ' as if it was updating the query, but the query does not show the updated fields such as "AgentCmpltd"
    32. rs.MoveNext
    33. End If
    34. End If
    35.    
    36. If rs.EOF = True Then
    37. msgbtn = MsgBox("There are currently no Call Back records!", vbInformation, "No Records")
    38. End If
    39.  
    40. If msgbtn = vbOK Then
    41. msgbtn2 = MsgBox("Would you like to quit the program now?", vbInformation + vbYesNo, "Quit?")
    42. If msgbtn2 = vbYes Then
    43. rs.Close
    44. End
    45.  
    46. Else
    47. 'do nothing
    48. End If
    49. End If
    50.  
    51. DisplayEnd:
    52.     Exit Sub
    53.  
    54. ErrorMsg:
    55.     If Err = Formclose Then
    56.     frmMsgboxLstRec.Show
    57.    End If
    58. Resume DisplayEnd
    59. End Sub
    60.  
    61. Private Sub Form_Activate()
    62. Dim msgbtn As Integer, strSelect As String
    63. Set rs = New Recordset
    64.  
    65. strSelect = "SELECT * FROM qryCompletedRef WHERE CallBackShift = '" & txtSalesShift.Text & "'"
    66. rs.Open strSelect, MyDataEnvironment.MyConnection, adOpenDynamic, adLockOptimistic
    67.  
    68.  
    69. If rs.RecordCount = 0 Then
    70. msgbtn = MsgBox("There are currently no Call Back records!", vbInformation, "No Records")
    71. Else
    72.     rs.MoveFirst
    73.     txtDateRef.Text = rs.Fields("DateRef")
    74.     txtCstmrFName.Text = rs.Fields("CustomerFName")
    75.     txtCstmrLName.Text = rs.Fields("CustomerLName")
    76.     txtSSNum.Text = rs.Fields("SS")
    77.     txtHSBCAcct.Text = rs.Fields("ExsistAcct")
    78.     If txtBrochOnly.Text = "" Or Null Then
    79.         'do nothing
    80.     Else
    81.         txtBrochOnly.Text = rs.Fields("BrochOnly")
    82.     End If
    83.     If txtBrochAddress.Text = "" Or Null Then
    84.         'do nothing
    85.     Else
    86.         txtBrochAddress.Text = rs.Fields("BrochAddress")
    87.     End If
    88.     txtCBPref.Text = rs.Fields("CallbackDate")
    89.     txtBestTime.Text = rs.Fields("BestTime")
    90.     txtCBShift.Text = rs.Fields("CallBackShift")
    91.     txtPriPhn.Text = rs.Fields("PrimaryPhone")
    92.    
    93.         If txtCallBackCmmnts.Text = "" Or Null Then
    94.             'do nothing
    95.         Else
    96.             txtCallBackCmmnts.Text = rs.Fields("CallbackComments")
    97.         End If
    98.         If txtSecPhn.Text = "" Or Null Then
    99.             'do nothing
    100.         Else
    101.             txtSecPhn.Text = rs.Fields("SecPhone")
    102.         End If
    103.         If txtChecking.Text = "" Or Null Then
    104.             'do nothing
    105.         Else
    106.             txtChecking.Text = rs.Fields("CHECKING")
    107.         End If
    108.         If txtSavings.Text = "" Or Null Then
    109.             'do nothing
    110.         Else
    111.             txtSavings.Text = rs.Fields("SAVINGS")
    112.         End If
    113.         If txtCredit.Text = "" Or Null Then
    114.             'do nothing
    115.         Else
    116.             txtCredit.Text = rs.Fields("CREDIT CARD")
    117.         End If
    118.         If txtATM.Text = "" Or Null Then
    119.             'DO NOTHING
    120.         Else
    121.             txtATM.Text = rs.Fields("ATM/MASTERMONEY")
    122.         End If
    123.         If txtSelect.Text = "" Or Null Then
    124.             'DO NOTHING
    125.         Else
    126.             txtSelect.Text = rs.Fields("SELECT CREDIT")
    127.         End If
    128.         If txtInsurance.Text = "" Or Null Then
    129.             'DO NOTHING
    130.         Else
    131.             txtInsurance.Text = rs.Fields("INSURANCE")
    132.         End If
    133.         If txtInvestments.Text = "" Or Null Then
    134.             'DO NOTHING
    135.         Else
    136.             txtInvestments.Text = rs.Fields("INVESTMENTS")
    137.         End If
    138.         If txtCD.Text = "" Or Null Then
    139.             'DO NOTHING
    140.         Else
    141.             txtCD.Text = rs.Fields("CD")
    142.         End If
    143.         If txtHomeEquity.Text = "" Or Null Then
    144.             'DO NOTHING
    145.         Else
    146.             txtHomeEquity.Text = rs.Fields("HOME EQUITY")
    147.         End If
    148.         If txtInstallment.Text = "" Or Null Then
    149.             'DO NOTHING
    150.         Else
    151.             txtInstallment.Text = rs.Fields("INSTALLMENT")
    152.         End If
    153.         If txtTuition.Text = "" Or Null Then
    154.             'DO NOTHING
    155.         Else
    156.             txtTuition.Text = rs.Fields("TUITION PLUS LOC")
    157.         End If
    158.         If txtOther.Text = "" Or Null Then
    159.             'DO NOTHING
    160.         Else
    161.             txtOther.Text = rs.Fields("OTHER")
    162.         End If
    163.         If txtFinalCmmnts.Text = "" Or Null Then
    164.             'DO NOTHING
    165.         Else
    166.             txtFinalCmmnts.Text = rs.Fields("FinalComments")
    167.         End If
    168.                    
    169. txtSlsRefNot.Text = rs.RecordCount
    170. End If
    171.  
    172. If msgbtn = vbOK Then
    173. Unload Me
    174.  
    175. End If
    176.  
    177.  
    178. rs.Close
    179.  
    180. End Sub
    As I stated I can not seem to get the recordset to move to the next record, and for that matter it is also not updating in the underlying query...

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    What is both strange & interesting is that when I do select the cmdNextRec button, it changes the recordcount of the underlying query as if something happened...

    Why I say that is strange is the query has criteria set up to sift out records from the Main table that do not meet certain criteria...

    So when this Call Back form is activated there is a textbox on the form that shows how many records are currently in the query...this is the same textbox that becomes adjusted when I click on Next...

    But the fields remain the same...and when I close the form and look at the Access query, nothing has changed!!

    I just thought that might help you to help me....

    Thank you!

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    While await any assistance on this important matter...I have been trying to test oout this problem on a demo form...and it all comes down to the fact that I cann not seem to get the recordset to move to the next record by using the MoveNext function....


    Can someone please show me how this works...


  7. #7
    Addicted Member
    Join Date
    Jul 2002
    Location
    BC, Canada
    Posts
    152
    Uh, I think you're missing an rs.Update call to update the recordset once you've changed it. I think that without this, the database does a rollback.

    Destined

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    With or without the rs.Update ...the recordset is till not moving to the next record!

    It has to have something to do with the rs.MoveNext...no idea why it is doing this?????

  9. #9
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    All these kind of line :
    VB Code:
    1. If txtOther.Text = "" Or Null Then
    2.             'DO NOTHING
    3.         Else
    4.             txtOther.Text = rs.Fields("OTHER")
    5.         End If

    should be change to :

    VB Code:
    1. If txtOther.Text <> "" Or txtOther.Text <> Null Then
    2.             txtOther.Text = rs.Fields("OTHER")
    3.         End If


    You cannot just put Or Null you need a condition

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    I appreciate that info, but that still does not solve this problem with the inability to move through the recordset....

    Also the fields were working fine with filling the fields with the appropriate data from the query...

  11. #11
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    ZIP your project, only put the relevant files in the folder...reduce the db size and e-mail me the project at: [email protected]
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  12. #12
    Addicted Member
    Join Date
    Jul 2002
    Location
    BC, Canada
    Posts
    152
    I was looking at your code earlier this morning, and I think that you're having logic errors, not that MoveNext isn't working.

    From what I remember looking at your code, you perform your query the same every time you click NextRecord. You automatically fill the textboxes, with the first value but never any other values? This is simply because you're not moving to the next record BEFORE you display the text.
    VB Code:
    1. Dim recordToDisplay As Integer
    2.  
    3. Private Sub Command1_Click()
    4.     Dim conn As New ADODB.Connection
    5.     Dim rs As New ADODB.Recordset
    6.     Dim counter As Integer
    7.    
    8.     conn.Provider = "Microsoft.Jet.OLEDB.4.0"
    9.     conn.Open "parts.mdb"
    10.    
    11.     rs.Open "SELECT * FROM Parts", conn
    12.    
    13.     ' since we clicked on moveNext, increment recordIndex
    14.     recordToDisplay = recordToDisplay + 1      
    15.    
    16.     ' ---- THIS IS THE PART YOU WANT!! -----
    17.     ' Now move to the record we want
    18.     counter = 0
    19.     While counter < recordToDisplay And Not rs.EOF
    20.         counter = counter + 1
    21.         rs.MoveNext
    22.     Wend
    23.    
    24.     If rs.EOF Then
    25.         MsgBox "cannot go past last record"
    26.         recordToDisplay = recordToDisplay - 1       ' so our current record isn't past EOF
    27.         GoTo CleanUp
    28.     End If
    29.    
    30.     txtData = rs!Cost
    31.    
    32. CleanUp:
    33.     rs.Close: conn.Close
    34.     Set rs = Nothing: Set conn = Nothing
    35.    
    36. End Sub
    Hope this helps.

    Destined
    Last edited by Destined Soul; Jun 19th, 2003 at 11:37 AM.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    Destined:

    I tested your code on a seperate form to see if I can get the recordset to move as desired and it only moved one record then stopped:

    Here is the code I used:

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim recordToDisplay As Integer
    3. Dim msgbtn As Integer, strSelect As String
    4. Dim con As New ADODB.Connection
    5. Dim rst As New ADODB.Recordset
    6. Dim counter As Integer
    7.  
    8. con.Provider = "Microsoft.Jet.OLEDB.4.0"
    9. con.Open "C:\My Documents\SalesTracking.mdb"
    10.  
    11. rst.Open "SELECT * FROM Main", con
    12.  
    13. recordToDisplay = recordToDisplay + 1
    14.  
    15. counter = 0
    16.     While counter < recordToDisplay And Not rst.EOF
    17.         counter = counter + 1
    18.         rst.MoveNext
    19.     Wend
    20.  
    21. If rst.EOF Then
    22.     MsgBox "Cannot go past last record."
    23.     recordToDisplay = recordToDisplay - 1
    24.     GoTo CleanUp
    25. Else
    26.     txtCstmrFName.Text = rst.Fields("CustomerFName")
    27.     txtCstmrLName.Text = rst.Fields("CustomerLName")
    28.     txtSSNum.Text = rst.Fields("SS")
    29.     txtSlsRefNot.Text = rst.RecordCount
    30. End If
    31.  
    32. CleanUp:
    33.  
    34. rst.Close: con.Close
    35. Set rst = Nothing
    36. Set con = Nothing
    37.  
    38. End Sub
    39. ____________________________________________________
    40.  
    41. Private Sub Form_Activate()
    42. Dim recordToDisplay As Integer
    43. Dim msgbtn As Integer, strSelect As String
    44. Dim con As New ADODB.Connection
    45. Dim rst As New ADODB.Recordset
    46. Dim counter As Integer
    47.  
    48. con.Provider = "Microsoft.Jet.OLEDB.4.0"
    49. con.Open "C:\My Documents\SalesTracking.mdb"
    50.  
    51. rst.Open "SELECT * FROM Main", con
    52.  
    53. recordToDisplay = recordToDisplay + 1
    54.  
    55. counter = 0
    56.     While counter < recordToDisplay And Not rst.EOF
    57.         counter = counter + 1
    58.         rst.MoveFirst
    59.     Wend
    60.  
    61. If rst.EOF Then
    62.     MsgBox "Cannot go past last record."
    63.     recordToDisplay = recordToDisplay - 1
    64.     GoTo CleanUp
    65. 'BELOW is used to avoid the 'INVALID USE OF NULL'
    66. 'error...because not all fields will have data in them
    67.  
    68. Else
    69.     If txtCstmrFName.Text = "" Or txtCstmrFName.Text = Null Then
    70.     'do nothing
    71.     Else
    72.     txtCstmrFName.Text = rst.Fields("CustomerFName")
    73.     End If
    74.     If txtCstmrLName.Text = "" Or txtCstmrLName.Text = Null Then
    75.     'do nothing
    76.     Else
    77.         txtCstmrLName.Text = rst.Fields("CustomerLName")
    78.         End If
    79.     If txtSSNum.Text = "" Or txtSSNum.Text = Null Then
    80.     'do nothing
    81.     Else
    82.     txtSSNum.Text = rst.Fields("SS")
    83.     End If
    84.     txtSlsRefNot.Text = rst.RecordCount
    85. End If
    86.  
    87.  
    88.  
    89. CleanUp:
    90.  
    91. rst.Close: con.Close
    92. Set rst = Nothing
    93. Set con = Nothing
    94.  
    95. End Sub
    mxnmx:

    I emailed you a scaled down copy of my project, I hope you can help...

    Thank you to all who are assisting me on this!!!

  14. #14
    Addicted Member
    Join Date
    Jul 2002
    Location
    BC, Canada
    Posts
    152
    Uh.. you put the declaration "Dim recordToDisplay As Integer" inside the click button. It should be outside, thus it will save the location value.

    By putting it inside, the variable is by default 0 (i think) and will never have a starting value other than that. Putting it outside, it will save its state, causing it to increment every time you click the button.

    Hope this helps,

    Destined

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    Ok Destined, I got the recordset to move next....so I will incorporate this into my real form...but one thing that I noticed is that within my code I have
    VB Code:
    1. txtSlsRefNot.Text = rst.RecordCount
    This is simply to show the number of records in that query...but when I run the code the textbox show -1, when in reality it should show a much higher number...

    Any idea why that happened?

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    Allright....so I made soem changs to my form with suggestions provided by Destined...and it still will not move to the next record...the counter will drop down by one but the textboxes will remain showing the 1st record data!!!

    Once again here is my code:

    VB Code:
    1. Private Sub cmdNextRec_Click()
    2. Const Formclose As Long = 3021
    3. On Error GoTo ErrorMsg
    4. Dim counter As Integer
    5. Dim msgbtn As Integer, strSelect As String, msgbtn2 As Integer
    6. Set rs = New Recordset
    7.  
    8. strSelect = "SELECT * FROM Main WHERE CallBackShift = '" & txtSalesShift.Text & "' AND AgentCmpltd <>'""'"
    9. rs.Open strSelect, MyDataEnvironment.MyConnection, adOpenDynamic, adLockOptimistic
    10.  
    11. recordToDisplay = recordToDisplay + 1
    12.  
    13. If txtSaleRep.Text = "" Then
    14. MsgBox "Please check the box to use the form before continuing!", vbCritical, "Your Name?"
    15. chkCB.SetFocus
    16. Exit Sub
    17. Else
    18. If lstAppGen.Text = "" Then
    19. MsgBox "Please select if an application was generated!", vbCritical, "Application Generated?"
    20. lstAppGen.SetFocus
    21. Exit Sub
    22. Else
    23. counter = 0
    24.     While counter < recordToDisplay And Not rs.EOF
    25.         counter = counter + 1
    26.         rs.MoveNext
    27.     Wend
    28.  
    29. If rs.EOF Then
    30.     msgbtn = MsgBox("There are currently no Call Back records!", vbInformation, "No Records")
    31.     recordToDisplay = recordToDisplay - 1
    32.     GoTo CleanUp
    33. Else
    34. chkCB.Value = 0
    35. rs.Fields("AgentCmpltd") = txtSaleRep.Text
    36. rs.Fields("CmpltdDate") = txtDateCmpltd.Text
    37. rs.Fields("AppGen") = lstAppGen.Text
    38. rs.Update
    39. txtSlsRefNot.Text = rs.RecordCount
    40. txtSlsRefNot.Text = rs.RecordCount - 1
    41.  
    42. End If
    43. End If
    44.    
    45.  
    46. If msgbtn = vbOK Then
    47. msgbtn2 = MsgBox("Would you like to quit the program now?", vbInformation + vbYesNo, "Quit?")
    48. If msgbtn2 = vbYes Then
    49. rs.Close
    50. End
    51.  
    52. Else
    53. 'do nothing
    54. End If
    55. End If
    56. End If
    57. DisplayEnd:
    58.     Exit Sub
    59.  
    60. ErrorMsg:
    61.     If Err = Formclose Then
    62.     frmMsgboxLstRec.Show
    63.    End If
    64. Resume DisplayEnd
    65.  
    66. CleanUp:
    67. rs.Close
    68. Set rs = Nothing
    69.  
    70. End Sub
    71. ____________________________________________________
    72. 'This subroutine seems to work fine...it is providing the 1st record
    73.  'from the SQL query
    74.  
    75. Private Sub Form_Activate()
    76. Dim msgbtn As Integer, strSelect As String
    77. Set rs = New Recordset
    78.  
    79. strSelect = "SELECT * FROM Main WHERE CallBackShift = '" & txtSalesShift.Text & "' AND AgentCmpltd <>'""'"
    80. rs.Open strSelect, MyDataEnvironment.MyConnection, adOpenDynamic, adLockOptimistic
    81.  
    82.  
    83. If rs.RecordCount = 0 Then
    84. msgbtn = MsgBox("There are currently no Call Back records!", vbInformation, "No Records")
    85. Else
    86.     rs.MoveFirst
    87.     txtDateRef.Text = rs.Fields("DateRef")
    88.     txtCstmrFName.Text = rs.Fields("CustomerFName")
    89.     txtCstmrLName.Text = rs.Fields("CustomerLName")
    90.     txtSSNum.Text = rs.Fields("SS")
    91.     txtHSBCAcct.Text = rs.Fields("ExsistAcct")
    92.     If txtBrochOnly.Text = "" Or Null Then
    93.         'do nothing
    94.     Else
    95.         txtBrochOnly.Text = rs.Fields("BrochOnly")
    96.     End If
    97.     If txtBrochAddress.Text = "" Or Null Then
    98.         'do nothing
    99.     Else
    100.         txtBrochAddress.Text = rs.Fields("BrochAddress")
    101.     End If
    102.     txtCBPref.Text = rs.Fields("CallbackDate")
    103.     txtBestTime.Text = rs.Fields("BestTime")
    104.     txtCBShift.Text = rs.Fields("CallBackShift")
    105.     txtPriPhn.Text = rs.Fields("PrimaryPhone")
    106.    
    107.         If txtCallBackCmmnts.Text = "" Or Null Then
    108.             'do nothing
    109.         Else
    110.             txtCallBackCmmnts.Text = rs.Fields("CallbackComments")
    111.         End If
    112.         If txtSecPhn.Text = "" Or Null Then
    113.             'do nothing
    114.         Else
    115.             txtSecPhn.Text = rs.Fields("SecPhone")
    116.         End If
    117.         If txtChecking.Text = "" Or Null Then
    118.             'do nothing
    119.         Else
    120.             txtChecking.Text = rs.Fields("CHECKING")
    121.         End If
    122.         If txtSavings.Text = "" Or Null Then
    123.             'do nothing
    124.         Else
    125.             txtSavings.Text = rs.Fields("SAVINGS")
    126.         End If
    127.         If txtCredit.Text = "" Or Null Then
    128.             'do nothing
    129.         Else
    130.             txtCredit.Text = rs.Fields("CREDIT CARD")
    131.         End If
    132.         If txtATM.Text = "" Or Null Then
    133.             'DO NOTHING
    134.         Else
    135.             txtATM.Text = rs.Fields("ATM/MASTERMONEY")
    136.         End If
    137.         If txtSelect.Text = "" Or Null Then
    138.             'DO NOTHING
    139.         Else
    140.             txtSelect.Text = rs.Fields("SELECT CREDIT")
    141.         End If
    142.         If txtInsurance.Text = "" Or Null Then
    143.             'DO NOTHING
    144.         Else
    145.             txtInsurance.Text = rs.Fields("INSURANCE")
    146.         End If
    147.         If txtInvestments.Text = "" Or Null Then
    148.             'DO NOTHING
    149.         Else
    150.             txtInvestments.Text = rs.Fields("INVESTMENTS")
    151.         End If
    152.         If txtCD.Text = "" Or Null Then
    153.             'DO NOTHING
    154.         Else
    155.             txtCD.Text = rs.Fields("CD")
    156.         End If
    157.         If txtHomeEquity.Text = "" Or Null Then
    158.             'DO NOTHING
    159.         Else
    160.             txtHomeEquity.Text = rs.Fields("HOME EQUITY")
    161.         End If
    162.         If txtInstallment.Text = "" Or Null Then
    163.             'DO NOTHING
    164.         Else
    165.             txtInstallment.Text = rs.Fields("INSTALLMENT")
    166.         End If
    167.         If txtTuition.Text = "" Or Null Then
    168.             'DO NOTHING
    169.         Else
    170.             txtTuition.Text = rs.Fields("TUITION PLUS LOC")
    171.         End If
    172.         If txtOther.Text = "" Or Null Then
    173.             'DO NOTHING
    174.         Else
    175.             txtOther.Text = rs.Fields("OTHER")
    176.         End If
    177.         If txtFinalCmmnts.Text = "" Or Null Then
    178.             'DO NOTHING
    179.         Else
    180.             txtFinalCmmnts.Text = rs.Fields("FinalComments")
    181.         End If
    182.                    
    183. txtSlsRefNot.Text = rs.RecordCount
    184. End If
    185.  
    186. If msgbtn = vbOK Then
    187. Unload Me
    188.  
    189. End If
    190.  
    191.  
    192. rs.Close
    193.  
    194. End Sub
    I am sure that I am doing something wrong

  17. #17
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    I got your project, I'm sorry to say but its not at all USER FRIENDLY. So you need to pull your socks up and work on it. The interface that you have can overwhelm the user, textboxes are all over the place...
    So take your first step on improving the interface and arrangments of all your controls.

    Your code is all complicated too, no commenting, no indenting!

    So what you should do is that- remove the dataenvironment and connect to your database like this:

    VB Code:
    1. 'Add a reference to ADO 2.7
    2. Dim getCnn As ADODB.Connection
    3. Dim Rs As ADODB.Recordset
    4.  
    5. Set getCnn = New ADODB.Connection
    6. getCnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\SalesTracking.mdb;"
    7. getCnn.Open
    8.  
    9. Set Rs = New Recordset
    10. Rs.Open Table1, getCnn, adOpenKeyset, adLockOptimistic
    11. 'Because you need to keep accessing your db all the time.
    12. 'Once you have opened the datasource whether a Table or SQL  
    13. 'query you can simply get data from it by:
    14.  
    15. Text1.Text=rs("Field Name")
    16.  
    17. 'And you can write to the db like this
    18.  
    19. rs("Field Name")=Text1.Text
    20.  
    21. 'And you can move on like this
    22.  
    23. rs.MoveNext

    You need to do improve your code so we can understand it here, and make your interface better so that the users of your app appreciate your work...

    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    mxnmx:

    I appreciate your candid response....I agree on all counts...this is by the way my first attempt at a project, and I agree that I can improve upon it greatly!!!

    I knew about the ADO connection through VBA, but when I got the VB6 and saw the dataenvironment, I thought that it would save time....

    But as I can see from many of you pro's in here, that sometimes the shortest line is not always the best!

    So I will "pull up my socks" and hit this again, with all of your suggestions in mind!

    Thank you once again...

    If I run into problem with the record not moving I will let you know.



    Sincerely,
    Salvatore

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    Hello mxnmx:

    Below is a revised version of 2 subroutines that I redid using your suggestions....I hope it looks better!

    The problem is that the recordset is till not moving to the next record...I can only guess that it has to do with the placement of the rs.MoveNext within the "cmdNextRec" click event:

    VB Code:
    1. Private Sub cmdNextRec_Click()
    2. Const Formclose As Long = 3021
    3. On Error GoTo ErrorMsg
    4.     'set ADO connection
    5. Dim con As ADODB.Connection
    6. Dim rs As ADODB.Recordset
    7. Dim strSelect As String, msgbtn As Integer, msgbtn2 As Integer
    8.  
    9. Set con = New ADODB.Connection
    10.  
    11. con.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=C:\My Documents\SalesTracking.mdb"
    12. con.Open
    13.  
    14. Set rs = New Recordset
    15. 'Setup query to pull only records that have not been looked at by a sales rep and
    16. '...called back
    17.  
    18. strSelect = "SELECT * FROM Main WHERE CallBackShift = '" & txtSalesShift.Text & "' AND AgentCmpltd <>'""'"
    19. rs.Open strSelect, MyDataEnvironment.MyConnection, adOpenKeyset, adLockOptimistic
    20.  
    21. 'we need to check and make sure that the user complete's the appropriate fields
    22. '...before continuing!
    23.  
    24. If txtSaleRep.Text = "" Then
    25.     MsgBox "Please check the box to use the form before continuing!", vbCritical, "Your Name?"
    26.     chkCB.SetFocus
    27.     Exit Sub
    28. Else
    29. If lstAppGen.Text = "" Then
    30.     MsgBox "Please select if an application was generated!", vbCritical, "Application Generated?"
    31.     lstAppGen.SetFocus
    32.     Exit Sub
    33. Else
    34.     'At the end of the recordset alert the user and close the connection
    35. If rs.EOF Then
    36.     msgbtn = MsgBox("There are currently no Call Back records!", vbInformation, "No Records")
    37.     GoTo CleanUp
    38.    
    39.     'otherwise move to the next record within the select query and update the
    40.     '...appropriate fields
    41. Else
    42.     rs.MoveNext
    43.     chkCB.Value = 0
    44.     rs("AgentCmpltd") = txtSaleRep.Text
    45.     rs("CmpltdDate") = txtDateCmpltd.Text
    46.     rs("AppGen") = lstAppGen.Text
    47.     txtSlsRefNot.Text = rs.RecordCount
    48.     txtSlsRefNot.Text = rs.RecordCount - 1
    49.  
    50. End If
    51.     End If
    52.    
    53.     'Ask the user if they want to quit the program since there are no more records
    54. If msgbtn = vbOK Then
    55.     msgbtn2 = MsgBox("Would you like to quit the program now?", vbInformation + vbYesNo, "Quit?")
    56. If msgbtn2 = vbYes Then
    57.     rs.Close
    58.     End
    59.  
    60. Else
    61.     'do nothing
    62. End If
    63.     End If
    64.         End If
    65.        
    66.     'To avoid the error '3021
    67. DisplayEnd:
    68.     Exit Sub
    69.  
    70. ErrorMsg:
    71.     If Err = Formclose Then
    72.     frmMsgboxLstRec.Show
    73.    End If
    74. Resume DisplayEnd
    75.  
    76.     'close connections
    77. CleanUp:
    78. rs.Close
    79. con.Close
    80. Set rs = Nothing
    81. Set con = Nothing
    82.  
    83. End Sub
    84. ____________________________________________________
    85.  
    86.  
    87. Private Sub Form_Activate()
    88. Dim msgbtn As Integer, strSelect As String
    89. Dim con As ADODB.Connection
    90. Dim rs As ADODB.Recordset
    91.  
    92.     'open the ADO connection to the Access database
    93. Set con = New ADODB.Connection
    94.  
    95. con.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=C:\My Documents\SalesTracking.mdb"
    96. con.Open
    97.  
    98. Set rs = New Recordset
    99.  
    100.     'set up the SELECT query to pull only customers who have not been called back
    101.    
    102. strSelect = "SELECT * FROM Main WHERE CallBackShift = '" & txtSalesShift.Text & "' AND AgentCmpltd <>'""'"
    103. rs.Open strSelect, MyDataEnvironment.MyConnection, adOpenKeyset, adLockOptimistic
    104.  
    105.     'check to see if there are records in the query, if not then move to the first
    106.     'record and fills the textboxes with the fields in the query
    107.    
    108. If rs.RecordCount = 0 Then
    109.     msgbtn = MsgBox("There are currently no Call Back records!", vbInformation, "No Records")
    110. Else
    111.     rs.MoveFirst
    112.     txtDateRef.Text = rs("DateRef")
    113.     txtCstmrFName.Text = rs("CustomerFName")
    114.     txtCstmrLName.Text = rs("CustomerLName")
    115.     txtSSNum.Text = rs("SS")
    116.     txtHSBCAcct.Text = rs("ExsistAcct")
    117.    
    118.     'The following If statements are to avoid a "Invalid Null" error message
    119.     'since these fields may or may not have data in them
    120.    
    121. If txtBrochOnly.Text = "" Or Null Then
    122.     'do nothing
    123. Else
    124.     txtBrochOnly.Text = rs("BrochOnly")
    125. End If
    126.  
    127. If txtBrochAddress.Text = "" Or Null Then
    128.     'do nothing
    129. Else
    130.     txtBrochAddress.Text = rs("BrochAddress")
    131. End If
    132.  
    133.     txtCBPref.Text = rs("CallbackDate")
    134.     txtBestTime.Text = rs("BestTime")
    135.     txtCBShift.Text = rs("CallBackShift")
    136.     txtPriPhn.Text = rs("PrimaryPhone")
    137.    
    138. If txtCallBackCmmnts.Text = "" Or Null Then
    139.      'do nothing
    140. Else
    141.      txtCallBackCmmnts.Text = rs("CallbackComments")
    142. End If
    143.  
    144. If txtSecPhn.Text = "" Or Null Then
    145.     'do nothing
    146. Else
    147.     txtSecPhn.Text = rs("SecPhone")
    148. End If
    149.  
    150. If txtChecking.Text = "" Or Null Then
    151.     'do nothing
    152. Else
    153.     txtChecking.Text = rs("CHECKING")
    154. End If
    155.  
    156. If txtSavings.Text = "" Or Null Then
    157.     'do nothing
    158. Else
    159.     txtSavings.Text = rs("SAVINGS")
    160. End If
    161.  
    162. If txtCredit.Text = "" Or Null Then
    163.     'do nothing
    164. Else
    165.     txtCredit.Text = rs("CREDIT CARD")
    166. End If
    167.  
    168. If txtATM.Text = "" Or Null Then
    169.     'DO NOTHING
    170. Else
    171.     txtATM.Text = rs("ATM/MASTERMONEY")
    172. End If
    173.  
    174. If txtSelect.Text = "" Or Null Then
    175.     'DO NOTHING
    176. Else
    177.     txtSelect.Text = rs("SELECT CREDIT")
    178. End If
    179.  
    180. If txtInsurance.Text = "" Or Null Then
    181.     'DO NOTHING
    182. Else
    183.     txtInsurance.Text = rs("INSURANCE")
    184. End If
    185.  
    186. If txtInvestments.Text = "" Or Null Then
    187.     'DO NOTHING
    188. Else
    189.     txtInvestments.Text = rs("INVESTMENTS")
    190. End If
    191.  
    192. If txtCD.Text = "" Or Null Then
    193.     'DO NOTHING
    194. Else
    195.     txtCD.Text = rs("CD")
    196. End If
    197.  
    198. If txtHomeEquity.Text = "" Or Null Then
    199.     'DO NOTHING
    200. Else
    201.     txtHomeEquity.Text = rs("HOME EQUITY")
    202. End If
    203.  
    204. If txtInstallment.Text = "" Or Null Then
    205.     'DO NOTHING
    206. Else
    207.     txtInstallment.Text = rs("INSTALLMENT")
    208. End If
    209.  
    210. If txtTuition.Text = "" Or Null Then
    211.     'DO NOTHING
    212. Else
    213.     txtTuition.Text = rs("TUITION PLUS LOC")
    214. End If
    215.  
    216. If txtOther.Text = "" Or Null Then
    217.     'DO NOTHING
    218. Else
    219.     txtOther.Text = rs("OTHER")
    220. End If
    221.  
    222. If txtFinalCmmnts.Text = "" Or Null Then
    223.     'DO NOTHING
    224. Else
    225.     txtFinalCmmnts.Text = rs("FinalComments")
    226. End If
    227.  
    228.     'show the total number of records in the query
    229. txtSlsRefNot.Text = rs.RecordCount
    230. End If
    231.  
    232.     'when there are no more records then close the form, and close connections
    233.  
    234. If msgbtn = vbOK Then
    235.     Unload Me
    236.  
    237. End If
    238.  
    239. rs.Close
    240. con.Close
    241. Set rs = Nothing
    242. Set con = Nothing
    243.  
    244. End Sub

  20. #20
    Addicted Member
    Join Date
    Jul 2002
    Location
    BC, Canada
    Posts
    152
    Hey Salvatore,

    If you could, give an explanation, in english, what you'd like to happen when you click on NextRecord?

    Is it something like:

    When user clicks button, validate the values entered by the user. If they're valid, update the corresponding recordset values to the ones the user entered, then increment the current record and display the values stored.

    Is this what you want?

    I noticed in your code that you do the sql query, but only after you've gotten the recordset do you validate the inputs. I'm guessing you'd probably want to change this order.

    As well, you're still not moving to the recordset that you're wanting to... verify my story and I'll give you a decent layout of what you probably want.

    Destined

  21. #21
    Addicted Member
    Join Date
    Jul 2002
    Location
    BC, Canada
    Posts
    152
    Assuming that my description is what you'd like to do, here's some sample code that opens an Access DB, and cycles back and forward through it, allowing for updating of the information. However, no code has been entered for Adding or Deleting an entire record.

    Hope this helps.

    Destined
    Attached Files Attached Files

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    Destined:

    What I am trying to accomplish to move through a recordset and update 3 fields.

    SO I have reps who will access this form and open to the first record...conduct the call back. They will need to enter their name and date and if an application was generated...so when they fill in these fields it should update the database when they go to the next record!

    I tried your suggestions, but i was not successful in updating the recordset...( im sure I ma doing something wrong!)

    I just need to know with the code I submittted last, what order the rs.MoveNext needs to be in, in relation to the rs.update, and how to show the fields from the next record????

    I hope this clarifies things

  23. #23

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    Can someone please larify something for me????????????

    I am still working on this stupid problem...I went back to my form and returned the textboxes to bound controls using a Dataenvironment...when I used the rs.MoveNext everything worked great....the only problem with that is I can not query using specific criteria!!!

    When I used an ADO connection I was unable to get the same results..

    VB Code:
    1. Private Sub Form_Activate ()
    2. Dim msgbtn As Integer, strSelect As String
    3. Dim con As ADODB.Connection
    4. Dim rs As ADODB.Recordset
    5.  
    6.     'open the ADO connection to the Access database
    7. Set con = New ADODB.Connection
    8.  
    9. con.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=C:\My Documents\SalesTracking.mdb"
    10. con.Open
    11.  
    12. Set rs = New Recordset
    13.  
    14.     'set up the SELECT query to pull only customers who have not been called back
    15.    
    16. strSelect = "SELECT * FROM Main WHERE CallBackShift = '" & txtSalesShift.Text & "' AND AgentCmpltd <>'""'"
    17. rs.Open strSelect, con, adOpenKeyset, adLockOptimistic
    18.  
    19.     'check to see if there are records in the query, if not then move to the first
    20.     'record and fills the textboxes with the fields in the query
    21.    
    22. If rs.RecordCount = 0 Then
    23.     msgbtn = MsgBox("There are currently no Call Back records!", vbInformation, "No Records")
    24. Else
    25.     rs.MoveFirst
    26.     txtDateRef.Text = rs("DateRef")
    27.     txtCstmrFName.Text = rs("CustomerFName")
    28.     txtCstmrLName.Text = rs("CustomerLName")
    29.     txtSSNum.Text = rs("SS")
    30.     txtHSBCAcct.Text = rs("ExsistAcct")
    31.    
    32.     'The following If statements are to avoid a "Invalid Null" error message
    33.     'since these fields may or may not have data in them
    34.    
    35. If txtBrochOnly.Text = "" Or Null Then
    36.     'do nothing
    37. Else
    38.     txtBrochOnly.Text = rs("BrochOnly")
    39. End If
    40.  
    41. If txtBrochAddress.Text = "" Or Null Then
    42.     'do nothing
    43. Else
    44.     txtBrochAddress.Text = rs("BrochAddress")
    45. End If
    46.  
    47.     txtCBPref.Text = rs("CallbackDate")
    48.     txtBestTime.Text = rs("BestTime")
    49.     txtCBShift.Text = rs("CallBackShift")
    50.     txtPriPhn.Text = rs("PrimaryPhone")
    51.    
    52. If txtCallBackCmmnts.Text = "" Or Null Then
    53.      'do nothing
    54. Else
    55.      txtCallBackCmmnts.Text = rs("CallbackComments")
    56. End If
    57.  
    58. If txtSecPhn.Text = "" Or Null Then
    59.     'do nothing
    60. Else
    61.     txtSecPhn.Text = rs("SecPhone")
    62. End If
    63.  
    64. If txtChecking.Text = "" Or Null Then
    65.     'do nothing
    66. Else
    67.     txtChecking.Text = rs("CHECKING")
    68. End If
    69.  
    70. If txtSavings.Text = "" Or Null Then
    71.     'do nothing
    72. Else
    73.     txtSavings.Text = rs("SAVINGS")
    74. End If
    75.  
    76. If txtCredit.Text = "" Or Null Then
    77.     'do nothing
    78. Else
    79.     txtCredit.Text = rs("CREDIT CARD")
    80. End If
    81.  
    82. If txtATM.Text = "" Or Null Then
    83.     'DO NOTHING
    84. Else
    85.     txtATM.Text = rs("ATM/MASTERMONEY")
    86. End If
    87.  
    88. If txtSelect.Text = "" Or Null Then
    89.     'DO NOTHING
    90. Else
    91.     txtSelect.Text = rs("SELECT CREDIT")
    92. End If
    93.  
    94. If txtInsurance.Text = "" Or Null Then
    95.     'DO NOTHING
    96. Else
    97.     txtInsurance.Text = rs("INSURANCE")
    98. End If
    99.  
    100. If txtInvestments.Text = "" Or Null Then
    101.     'DO NOTHING
    102. Else
    103.     txtInvestments.Text = rs("INVESTMENTS")
    104. End If
    105.  
    106. If txtCD.Text = "" Or Null Then
    107.     'DO NOTHING
    108. Else
    109.     txtCD.Text = rs("CD")
    110. End If
    111.  
    112. If txtHomeEquity.Text = "" Or Null Then
    113.     'DO NOTHING
    114. Else
    115.     txtHomeEquity.Text = rs("HOME EQUITY")
    116. End If
    117.  
    118. If txtInstallment.Text = "" Or Null Then
    119.     'DO NOTHING
    120. Else
    121.     txtInstallment.Text = rs("INSTALLMENT")
    122. End If
    123.  
    124. If txtTuition.Text = "" Or Null Then
    125.     'DO NOTHING
    126. Else
    127.     txtTuition.Text = rs("TUITION PLUS LOC")
    128. End If
    129.  
    130. If txtOther.Text = "" Or Null Then
    131.     'DO NOTHING
    132. Else
    133.     txtOther.Text = rs("OTHER")
    134. End If
    135.  
    136. If txtFinalCmmnts.Text = "" Or Null Then
    137.     'DO NOTHING
    138. Else
    139.     txtFinalCmmnts.Text = rs("FinalComments")
    140. End If
    141.  
    142.     'show the total number of records in the query
    143. txtSlsRefNot.Text = rs.RecordCount
    144. End If
    145.  
    146.     'when there are no more records then close the form, and close connections
    147.  
    148. If msgbtn = vbOK Then
    149.     Unload Me
    150.  
    151. End If
    152.  
    153. rs.Close
    154. con.Close
    155. Set rs = Nothing
    156. Set con = Nothing
    157.  
    158. End Sub

    This code fills the fields correctly...but it is when the user enters data into a field to change the underlying database table and then move to the next record, is where I am pulling my hair!!!

    Logic tells me that when I want to move to a new record I have to populate the fields with data from the next record, while also updating the last one...

    Can someone please help me to understand what I am doing wrong????

  24. #24
    Addicted Member
    Join Date
    Jul 2002
    Location
    BC, Canada
    Posts
    152
    Hey Salvatore,

    I was wondering if you've had time to look at my code? I'm pretty sure it does exactly what you want to do, although it's done on a different database.

    If you haven't had a look at it, I suggest you do as it might help you with your problem.

    If not, email me your code. destined_soul@_________ where you fill the ___ with hotmail.com.

    Destined

  25. #25

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    Destined:

    I got an opportunity to work on this form using your suggestions....and I ran into a familiar problem with the rs.MoveFirst function:

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     Dim sqlStr As String
    4.     Set conn = New ADODB.Connection
    5.     Set rs = New ADODB.Recordset
    6.    
    7.     conn.Provider = "Microsoft.Jet.OLEDB.4.0"
    8.     conn.Open App.Path & "\SalesTracking.mdb"
    9.     conn.BeginTrans
    10.    
    11.     sqlStr = "SELECT * FROM Main WHERE CallBackShift = '" & txtSalesShift.Text & "' AND AgentCmpltd <>'""'"
    12.    
    13.     ' If I recall correctly, only adOpenStatic or adOpenKeyset actually
    14.     ' fills rs.recordCount with a value other than -1
    15.    
    16.     rs.Open sqlStr, conn, adOpenStatic, adLockOptimistic
    17.     rs.MoveFirst
    18.    
    19.     If rs.EOF Then
    20.         MsgBox "No records found, exiting program"
    21.         Unload Me
    22.         End
    23.     End If
    24.    
    25.     rs.MoveFirst
    26.    
    27.     FillInformation
    28.     AdjustEnabledButtons
    29.    
    30.     currIndex = 1
    31.     modificationsApplied = False
    32.    
    33. End Sub
    I am getting run-time error3021 - Either EOF or BOF is True, or the current record has been deleted; it requires a current record!

    I can not seem to get past this...there are records in the database???

  26. #26
    Addicted Member
    Join Date
    Jul 2002
    Location
    BC, Canada
    Posts
    152
    I think I know why you're getting that strange error, and it's quite logical. I've been playing with your code for a bit, and the whole time, nothing happened... until now. I looked over the query, and what it turns out is that the fields are (somehow) non-null, but that they're empty strings!!!!

    Thus "WHERE field IS Null" will fail.

    I'm not sure of the "proper" syntax, but here's what I found to use after a little bit:

    "WHERE (AgentCmpltd IS Null OR Ltrim(Rtrim(AgentCmpltd)) = '')"

    Note that the LTrim(....) = '' uses two single quotes ', not a double " quote.

    Destined

  27. #27

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    Destined:

    It is still unsuccessful!!! When I first run the form, it appears to show the accurate first record in the table, but when I attempt to change the data in 3 of the fields and then move to the next record, NOTHING happens!

    I know that I am still learning, but I am curious, within the code of the cmdNextRec:

    VB Code:
    1. If Not UpdateDBInformation Then Exit Sub
    2.  
    3. rs.MoveNext
    4. currIndex = currIndex +1
    5.  
    6. FillInformation
    7. AdjustEnableButtons
    But how does the rs.MoveNext function know to use the appropriate recordset???

    Because the query is opened within the form load...and the cmdNextRec (from what I can see) is only referring to the variable rs which is declared as a Recordset....could this be why it is not moving?

    The other thing is that when I add a name to the Sales Rep field while in run mode, and then Quit, it is not updating the underlying table....

    I will be working on this problem all day today, so if there is anything that comes to mind, please do not hesitate to let me know

    THANK YOU!

  28. #28
    Addicted Member
    Join Date
    Jul 2002
    Location
    BC, Canada
    Posts
    152
    Hey Salvatore,

    I'm just getting ready for work, but here's some stuff to think about.

    But how does the rs.MoveNext function know to use the appropriate recordset???
    Ah. This is probably the biggest issue you have to deal with. Although your code has the ability to work, you need to ask yourself what the user should do. Does the user HAVE TO fill out the current record being displayed before moving to the next record? For the moment, your code forces you to have to finish dealing with that one record.

    Although I am not the designer of the program, I'd suggest looking into maybe having MoveNext/Prev just cycle through the database without applying any changes to the recordset. To be able to 'save' changes to a record, I'd probably make a 'Save Changes' button that checks the fields and then updates the recordset if everything's ok. If you did this, you would also want to ask if you'd requery the database once a save was made.

    I say this because once I got the program working (ish) on my end, it always wanted to update the fields even if I didn't change anything. Another idea may be to just have it message ("Some fields are invalid, would you like to not save them and continue?", vbYesNo... if yes then just movenext, else highlight error.) Again, these are just some thoughts. You probably have an idea of what it should do, I'd hope. hehee...

    Because the query is opened within the form load...and the cmdNextRec (from what I can see) is only referring to the variable rs which is declared as a Recordset....could this be why it is not moving?
    No. It is not moving because UpdateDBInformation is return false. In the code, you have
    VB Code:
    1. Private Function UpdateDBInformation() As Boolean
    2.     If rs.EditMode = adEditInProgress Then
    3.         ...
    4.     End If
    5. End Function
    This is a problem, since the only place in your code where you edit the recordset (ie: rs!Name = "Bob") within the if statement!! By default, a boolean function will return false. Thus, in your cmdMoveNext, you will always exit the sub before being able to call rs.MoveNext. Solution: you don't need the if rs.EditMode = ..., just cut that if statement out from around the inner code (and it's "end if") and you should see it move...

    The other thing is that when I add a name to the Sales Rep field while in run mode, and then Quit, it is not updating the underlying table....
    Ah, yes. Well, since you will never get into updating the fields in the recordset, you will never set your flag "modificationsApplied" to True. Thus, every time the form unloads, you will rollback the transaction.

    Hope some of this helps. I'll check with you throughout the day when I can.

    Oh, one more thing. You should try indenting a little more so I don't have to when I get the program. :P Just makes it a lot easier to read the logic of the program. I'm not sure where some good pointers are, though.

    Oh well, off to work. (Summer student, temp, doing a vb interface for a ms access db. )

    Destined

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width