473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Recordset Navigation problem - MoveNext do not execute

4
I would like to access recordset object in the entire module. I have made the recordset global, but the MoveNext is not executing. Please help! Any ideas as to why.

Thank you in advance!
Sep 23 '10 #1
7 4442
Stewart Ross
2,545 Expert Mod 2GB
Could you post the code for what you are trying to achieve? I'd be certain that MoveNext is working fine - it is how you are trying to apply your recordset that is the problem. If you are using a form and create a recordset using recordsetclone, the two recordsets are entirely independent. Movenext in your cloned recordset will not cause any change in the Form's recordset.

-Stewart
Sep 23 '10 #2
EvaH
4
Thank you for your help! Your help is truly appreciated!

My code follows:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Option Compare Database
  3. Public varBookmark As Variant
  4. Private rs1 As ADODB.Recordset
  5. Public lngTotalRec As Long
  6.  
  7.  
  8. '--WHEN THE USER CLICK THE VIEW BUTTON, BASED ON THE '--SELECTION CRITERIA THE QUERY IS BUILT.
  9.  
  10. Private Sub ViewCmd_Click()
  11.  
  12. Debug.Print Form.Name
  13.  
  14. DoCmd.SetWarnings False
  15.  
  16. If IsNull(Me.clientid) Then
  17.    MsgBox "Please enter or select a CLIENT NAME"
  18.    Exit Sub
  19. End If
  20.  
  21. Dim Conn As ADODB.Connection
  22. Set Conn = CurrentProject.Connection
  23. 'Dim rs1 As New ADODB.Recordset
  24. 'rs1.ActiveConnection = Conn
  25.  
  26. Set rs1 = New ADODB.Recordset
  27. rs1.ActiveConnection = Conn
  28.  
  29.  
  30. Dim strSQL As String
  31. Dim blnCalcTotalRecs As Boolean
  32. blnCalcTotalRecs = True
  33.  
  34. Debug.Print Me.clientid
  35. Debug.Print Me.JobNumber
  36. Debug.Print Me.CampaignType
  37. Debug.Print Me.MailerStatus
  38.  
  39. Debug.Print Forms!frmclientmailschedule!clientid
  40. Debug.Print Forms!frmclientmailschedule!CampaignType
  41. Debug.Print Forms!frmclientmailschedule!MailerStatus
  42.  
  43.  
  44. If Not IsNull(Me.JobNumber) Or _
  45.    Not IsNull(Me.CampaignType) Or _
  46.    Not IsNull(Me.MailerStatus) Then
  47.    If Not IsNull(Me.JobNumber) Then
  48.       strSQL = "select *" & _
  49.                 " from tblClientMailSchedule" & _
  50.                 " where clientid = " & Me.clientid & _
  51.                 " and jobnumber = '" & Me.JobNumber & "';"
  52.  
  53.    Else
  54.        If Not IsNull(Me.CampaignType) And Not IsNull(Me.MailerStatus) Then
  55.           strSQL = "select *" & _
  56.                 " from tblClientMailSchedule" & _
  57.                 " where clientid = " & Me.clientid & _
  58.                 " and campaigntype = '" & Me.CampaignType & "'" & _
  59.                 " and mailerstatus = '" & Me.MailerStatus & "'" & _
  60.                 " order by startdate;"
  61.        Else
  62.           If Not IsNull(Me.CampaignType) Then
  63.              strSQL = "select *" & _
  64.                 " from tblClientMailSchedule" & _
  65.                  " where clientid = " & Me.clientid.Value & _
  66.                 " and campaigntype = '" & Me.CampaignType.Value & "'" & _
  67.                 " order by startdate;"
  68.           Else
  69.              If Not IsNull(Me.MailerStatus) Then
  70.                 strSQL = "select *" & _
  71.                    " from tblClientMailSchedule" & _
  72.                    " where clientid = " & Me.clientid.Value & _
  73.                    " and mailerstatus = '" & Me.MailerStatus.Value & "'" & _
  74.                    " order by startdate;"
  75.              End If
  76.           End If
  77.        End If
  78.    End If
  79. Else
  80.    strSQL = "select * " & _
  81.             "from tblClientMailSchedule" & _
  82.             " where clientid = " & Me.clientid.Value & _
  83.             " order by startdate ; "
  84. End If
  85.  
  86. Debug.Print strSQL
  87.  
  88. rs1.Open strSQL, Conn, adOpenKeyset, adLockOptimistic
  89.  
  90. If rs1.BOF Or rs1.EOF Then
  91.    MsgBox "NO SCHEDULE EXIST FOR CLIENT - Please verify your selection criteria"
  92.    Exit Sub
  93. End If
  94.  
  95. Call Move_Record_To_Form
  96.  
  97.  
  98. End Sub
  99.  
  100.  
  101. '-- THE MOVE_RECORD_TO_FORM, MOVES THE DATA OF THE '--RECORDSET TO THE FORM
  102.  
  103. Public Sub Move_Record_To_Form()
  104.  
  105. 'Public Sub Move_Record_To_Form(ByRef rs1 As ADODB.Recordset)
  106.  
  107. clientid.Value = rs1![clientid]
  108. JobNumber.Value = rs1![JobNumber]
  109. CampaignType.Value = rs1![CampaignType]
  110. StartDate.Value = rs1![StartDate]
  111. EndDate.Value = rs1![EndDate]
  112. MailerStatus.Value = rs1![MailerStatus]
  113. MailingName.Value = rs1![MailingName]
  114. TriggerSegment.Value = rs1![TriggerSegment]
  115. TSName.Value = rs1![TSName]
  116. MailingFrequency.Value = rs1![MailingFrequency]
  117. NbrMailingDay.Value = rs1![NbrMailingDay]
  118. DataSource.Value = rs1![DataSource]
  119. RemoteAccess.Value = rs1![RemoteAccess]
  120. reportid.Value = rs1![reportid]
  121. NbrDLDay.Value = rs1![NbrDLDay]
  122. Comments.Value = rs1![Comments]
  123. 'ScheduleID.Value = rs1![ScheduleID]
  124.  
  125.  
  126. Dim position
  127. Dim SearchString As String
  128.  
  129. If Not IsNull(rs1!MailingDays) Then
  130.    SearchString = rs1!MailingDays
  131.  
  132.    position = InStr(1, SearchString, "1", 1)
  133.    If position > 0 Then
  134.       ChkMailSun.Value = 1
  135.    End If
  136.  
  137.    position = InStr(1, SearchString, "2", 1)
  138.    If position > 0 Then
  139.       ChkMailMon.Value = 1
  140.    End If
  141.  
  142.    position = InStr(1, SearchString, "3", 1)
  143.    If position > 0 Then
  144.       ChkMailTue.Value = 1
  145.    End If
  146.  
  147.    position = InStr(1, SearchString, "4", 1)
  148.    If position > 0 Then
  149.       ChkMailWed.Value = 1
  150.    End If
  151.  
  152.    position = InStr(1, SearchString, "5", 1)
  153.    If position > 0 Then
  154.       ChkMailThu.Value = 1
  155.    End If
  156.  
  157.    position = InStr(1, SearchString, "6", 1)
  158.    If position > 0 Then
  159.       ChkMailFri.Value = 1
  160.    End If
  161.  
  162.    position = InStr(1, SearchString, "7", 1)
  163.    If position > 0 Then
  164.       ChkMailSat.Value = 1
  165.    End If
  166. End If
  167.  
  168. If Not IsNull(rs1!DownloadDays) Then
  169.    SearchString = rs1!DownloadDays
  170.  
  171.    position = InStr(1, SearchString, "1", 1)
  172.    If position > 0 Then
  173.       ChkDLSun.Value = 1
  174.    End If
  175.  
  176.    position = InStr(1, SearchString, "2", 1)
  177.    If position > 0 Then
  178.       ChkDLMon.Value = 1
  179.    End If
  180.  
  181.    position = InStr(1, SearchString, "3", 1)
  182.    If position > 0 Then
  183.       ChkDLTue.Value = 1
  184.    End If
  185.  
  186.    position = InStr(1, SearchString, "4", 1)
  187.    If position > 0 Then
  188.       ChkDLWed.Value = 1
  189.    End If
  190.  
  191.    position = InStr(1, SearchString, "5", 1)
  192.    If position > 0 Then
  193.       ChkDLThu.Value = 1
  194.    End If
  195.  
  196.    position = InStr(1, SearchString, "6", 1)
  197.    If position > 0 Then
  198.       ChkDLFri.Value = 1
  199.    End If
  200.  
  201.    position = InStr(1, SearchString, "7", 1)
  202.    If position > 0 Then
  203.       ChkDLSat.Value = 1
  204.    End If
  205. End If
  206.  
  207. 'Dim varBookmark As Variant
  208. rs1.MoveLast
  209. lngTotalRec = rs1.RecordCount
  210. rs1.MoveFirst
  211. varBookmark = rs1.Bookmark
  212. Me.txtRecordNo = "Record " & Me.CurrentRecord & " of " & lngTotalRec
  213.  
  214. FirstRecBtn.Enabled = True
  215. PrevRecBtn.Enabled = True
  216. NextRecBtn.Enabled = True
  217. LastRecBtn.Enabled = True
  218.  
  219. End Sub
  220.  
  221. '--IF THE USER CLICK THE NEXT NAVIGATION BUTTON THE '--FOLLOWING CODE IS EXECUTED. THIS IS WHERE THE '--MOVENEXT COMMAND APPEAR TO NOT EXECUTE.  THE '--ME.CURRENTRECORD IS NOT UPDATING ON THE FORM.
  222.  
  223. Private Sub NextRecbtn_Click()
  224.  
  225. rs1.MoveNext
  226.  
  227. Me.txtRecordNo = "Record " & Me.CurrentRecord & " of " & lngTotalRec
  228.  
  229. Call Move_Record_To_Form()
  230.  
  231. MsgBox "Move To Next Record"
  232.  
  233.  
  234. End Sub
  235.  
  236.  
Sep 23 '10 #3
Stewart Ross
2,545 Expert Mod 2GB
Hi again. Can I check that the controls in your form are unbound - that is, that they are not associated with a specific recordsource table or query? You appear to be looking up records from a recordset then, in your Move_Record_To_Form function, setting each of your controls to the current recordset record. This will only work if the form is unbound - otherwise you will be setting values of the current record associated withyour form to values from a different record, with the likely outcome of creating duplicates which violate relational constraints.

Assuming it is an unbound form, when Movenext is called, you update the record count (line 227). Does this change as you would expect? If it does, then at least you know that the recordset has advanced by one.

What happens when you reach end of file? Your Movenext at present is followed by your Move_Record_To_Form without testing for rs1.eof, which must happen at some stage when you keep moving from record to record.

As an observation I would point out that the approach you are taking is hard for others to verify. In my opinion, it is simpler instead of using unbound controls to change the recordsource of a bound form so that the recordsource becomes your SQL statement, meaning that Access will take care of displaying records, moving from one to the next, dealing with EOF, and so on.

You can do this after you form your SQL string just by setting Me.Recordsource = strSQL. There are occasions when it may be essential to work on an unbound form, but it does make it complicated to do simple things like moving from one record to the next.

-Stewart
Sep 23 '10 #4
EvaH
4
Hi Stewart

Thanks so much for your help!

My form is bound, so do you think it is best to use an unbound form?
Sep 24 '10 #5
MOCaseA
34
I think what he is trying to say is that you need to verify that each source field is unbound... I may be wrong though...
Sep 24 '10 #6
EvaH
4
I am new to access...so please excuse my ignorance.

So should the form be a bound form, the form is currently bound. What do you mean by "source field unbound?
Sep 24 '10 #7
Stewart Ross
2,545 Expert Mod 2GB
Hi. You are making life very complicated for yourself; you cannot use a bound form and then try to fill records from a code recordset. What you are actually doing is overwriting the currently-bound record each time you move a record from your recordset. There is no need at all to do any of this; as I mentioned, you can replace the form's recordsource with your SQL statement. However, these are all advanced techniques, and in my opinion you are trying to do things for which you have not got enough experience as yet.

Be aware, as I mentioned in my reply, that if you set the current record in your bound form to values already existing in your recordset you will create a duplicate record - you are NOT retrieving that specific record at all, you are creating a NEW record that is an exact DUPLICATE of the one you've moved.

This cannot work, as whatever the key fields are you have just set another record to the same key values, which Access will not allow (if it is set up with the correct relationships).

I am NOT recommending you use an unbound form, as it's so much work doing it like this - but what you are attempting to do will only work if your form IS unbound.

I am recommending a complete rethink of your approach; you can use the recordset's Clone facilities to generate a replica of the form's recordset, use the recordset's Find function to find any matching records, and its Bookmark properties to match the form back to the records found - just search MSDN for recordset clone and bookmark references. However, in my opinion you've a lot of backtracking to do before you will understand how to do it.

-Stewart
Sep 24 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: dmiller23462 | last post by:
My brain is nuked....Can anybody tell me right off the bat what is wrong with this code? Along with any glaring errors, please let me know the syntax to display a message (Response.Write would be...
0
by: mad | last post by:
I am new here and don't know if someone has encountered and discussed this problem before. I appreciate any help to this problem. I am building a new Oracle database (8.1.7) and Win 2000/IIS 5...
22
by: Gerry Abbott | last post by:
Hi all, I having some confusing effects with recordsets in a recent project. I created several recordsets, each set with the same number of records, and related with an index value. I create...
3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
18
by: Darryl Kerkeslager | last post by:
When I open an ADO Recordset, I close it. However, it seems that there may be some difference in this manner of opening a Recordset: Dim rL As ADODB.Recordset Set rL = New ADODB.Recordset ...
1
by: praveen79hebbar | last post by:
Hi, I have written a code to navigate through the recordset using MoveFirst,Movenext,MovePrevious and MoveLast i would like to fetch the records from the database and display it on a form in...
36
by: beebelbrox | last post by:
Hi, I am new VB programming in Access and I am requesting help with the following code. WIndows OS MSaccess 2003 This code is attached to an unbound form that will display a specific recordset...
6
by: Gilgamesh | last post by:
How do I pass a result of a stored procedure from a C# assembly to a VB 6 so VB can see the result as RecordSet? Thanks, Gilgamesh
2
by: wallconor | last post by:
Hi, I am having a problem using Dreamweaver CS3 standard recordset paging behavior. It doesn’t seem to work when I pass parameter values from a FORM on my search page, to the recordset on my...
0
by: emalcolm_FLA | last post by:
Hello and TIA for your consideration. I have created several db's for a non-profit and they want custom navigation buttons to display "You are on the first record, last record, etc". With this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.