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!
7 4442
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
Thank you for your help! Your help is truly appreciated!
My code follows: -
-
Option Compare Database
-
Public varBookmark As Variant
-
Private rs1 As ADODB.Recordset
-
Public lngTotalRec As Long
-
-
- '--WHEN THE USER CLICK THE VIEW BUTTON, BASED ON THE '--SELECTION CRITERIA THE QUERY IS BUILT.
-
-
Private Sub ViewCmd_Click()
-
-
Debug.Print Form.Name
-
-
DoCmd.SetWarnings False
-
-
If IsNull(Me.clientid) Then
-
MsgBox "Please enter or select a CLIENT NAME"
-
Exit Sub
-
End If
-
-
Dim Conn As ADODB.Connection
-
Set Conn = CurrentProject.Connection
-
'Dim rs1 As New ADODB.Recordset
-
'rs1.ActiveConnection = Conn
-
-
Set rs1 = New ADODB.Recordset
-
rs1.ActiveConnection = Conn
-
-
-
Dim strSQL As String
-
Dim blnCalcTotalRecs As Boolean
-
blnCalcTotalRecs = True
-
-
Debug.Print Me.clientid
-
Debug.Print Me.JobNumber
-
Debug.Print Me.CampaignType
-
Debug.Print Me.MailerStatus
-
-
Debug.Print Forms!frmclientmailschedule!clientid
-
Debug.Print Forms!frmclientmailschedule!CampaignType
-
Debug.Print Forms!frmclientmailschedule!MailerStatus
-
-
-
If Not IsNull(Me.JobNumber) Or _
-
Not IsNull(Me.CampaignType) Or _
-
Not IsNull(Me.MailerStatus) Then
-
If Not IsNull(Me.JobNumber) Then
-
strSQL = "select *" & _
-
" from tblClientMailSchedule" & _
-
" where clientid = " & Me.clientid & _
-
" and jobnumber = '" & Me.JobNumber & "';"
-
-
Else
-
If Not IsNull(Me.CampaignType) And Not IsNull(Me.MailerStatus) Then
-
strSQL = "select *" & _
-
" from tblClientMailSchedule" & _
-
" where clientid = " & Me.clientid & _
-
" and campaigntype = '" & Me.CampaignType & "'" & _
-
" and mailerstatus = '" & Me.MailerStatus & "'" & _
-
" order by startdate;"
-
Else
-
If Not IsNull(Me.CampaignType) Then
-
strSQL = "select *" & _
-
" from tblClientMailSchedule" & _
-
" where clientid = " & Me.clientid.Value & _
-
" and campaigntype = '" & Me.CampaignType.Value & "'" & _
-
" order by startdate;"
-
Else
-
If Not IsNull(Me.MailerStatus) Then
-
strSQL = "select *" & _
-
" from tblClientMailSchedule" & _
-
" where clientid = " & Me.clientid.Value & _
-
" and mailerstatus = '" & Me.MailerStatus.Value & "'" & _
-
" order by startdate;"
-
End If
-
End If
-
End If
-
End If
-
Else
-
strSQL = "select * " & _
-
"from tblClientMailSchedule" & _
-
" where clientid = " & Me.clientid.Value & _
-
" order by startdate ; "
-
End If
-
-
Debug.Print strSQL
-
-
rs1.Open strSQL, Conn, adOpenKeyset, adLockOptimistic
-
-
If rs1.BOF Or rs1.EOF Then
-
MsgBox "NO SCHEDULE EXIST FOR CLIENT - Please verify your selection criteria"
-
Exit Sub
-
End If
-
-
Call Move_Record_To_Form
-
-
-
End Sub
-
-
- '-- THE MOVE_RECORD_TO_FORM, MOVES THE DATA OF THE '--RECORDSET TO THE FORM
-
-
Public Sub Move_Record_To_Form()
-
-
'Public Sub Move_Record_To_Form(ByRef rs1 As ADODB.Recordset)
-
-
clientid.Value = rs1![clientid]
-
JobNumber.Value = rs1![JobNumber]
-
CampaignType.Value = rs1![CampaignType]
-
StartDate.Value = rs1![StartDate]
-
EndDate.Value = rs1![EndDate]
-
MailerStatus.Value = rs1![MailerStatus]
-
MailingName.Value = rs1![MailingName]
-
TriggerSegment.Value = rs1![TriggerSegment]
-
TSName.Value = rs1![TSName]
-
MailingFrequency.Value = rs1![MailingFrequency]
-
NbrMailingDay.Value = rs1![NbrMailingDay]
-
DataSource.Value = rs1![DataSource]
-
RemoteAccess.Value = rs1![RemoteAccess]
-
reportid.Value = rs1![reportid]
-
NbrDLDay.Value = rs1![NbrDLDay]
-
Comments.Value = rs1![Comments]
-
'ScheduleID.Value = rs1![ScheduleID]
-
-
-
Dim position
-
Dim SearchString As String
-
-
If Not IsNull(rs1!MailingDays) Then
-
SearchString = rs1!MailingDays
-
-
position = InStr(1, SearchString, "1", 1)
-
If position > 0 Then
-
ChkMailSun.Value = 1
-
End If
-
-
position = InStr(1, SearchString, "2", 1)
-
If position > 0 Then
-
ChkMailMon.Value = 1
-
End If
-
-
position = InStr(1, SearchString, "3", 1)
-
If position > 0 Then
-
ChkMailTue.Value = 1
-
End If
-
-
position = InStr(1, SearchString, "4", 1)
-
If position > 0 Then
-
ChkMailWed.Value = 1
-
End If
-
-
position = InStr(1, SearchString, "5", 1)
-
If position > 0 Then
-
ChkMailThu.Value = 1
-
End If
-
-
position = InStr(1, SearchString, "6", 1)
-
If position > 0 Then
-
ChkMailFri.Value = 1
-
End If
-
-
position = InStr(1, SearchString, "7", 1)
-
If position > 0 Then
-
ChkMailSat.Value = 1
-
End If
-
End If
-
-
If Not IsNull(rs1!DownloadDays) Then
-
SearchString = rs1!DownloadDays
-
-
position = InStr(1, SearchString, "1", 1)
-
If position > 0 Then
-
ChkDLSun.Value = 1
-
End If
-
-
position = InStr(1, SearchString, "2", 1)
-
If position > 0 Then
-
ChkDLMon.Value = 1
-
End If
-
-
position = InStr(1, SearchString, "3", 1)
-
If position > 0 Then
-
ChkDLTue.Value = 1
-
End If
-
-
position = InStr(1, SearchString, "4", 1)
-
If position > 0 Then
-
ChkDLWed.Value = 1
-
End If
-
-
position = InStr(1, SearchString, "5", 1)
-
If position > 0 Then
-
ChkDLThu.Value = 1
-
End If
-
-
position = InStr(1, SearchString, "6", 1)
-
If position > 0 Then
-
ChkDLFri.Value = 1
-
End If
-
-
position = InStr(1, SearchString, "7", 1)
-
If position > 0 Then
-
ChkDLSat.Value = 1
-
End If
-
End If
-
-
'Dim varBookmark As Variant
-
rs1.MoveLast
-
lngTotalRec = rs1.RecordCount
-
rs1.MoveFirst
-
varBookmark = rs1.Bookmark
-
Me.txtRecordNo = "Record " & Me.CurrentRecord & " of " & lngTotalRec
-
-
FirstRecBtn.Enabled = True
-
PrevRecBtn.Enabled = True
-
NextRecBtn.Enabled = True
-
LastRecBtn.Enabled = True
-
-
End Sub
-
- '--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.
-
-
Private Sub NextRecbtn_Click()
-
-
rs1.MoveNext
-
-
Me.txtRecordNo = "Record " & Me.CurrentRecord & " of " & lngTotalRec
-
-
Call Move_Record_To_Form()
-
-
MsgBox "Move To Next Record"
-
-
-
End Sub
-
-
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
Hi Stewart
Thanks so much for your help!
My form is bound, so do you think it is best to use an unbound form?
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...
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?
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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
...
|
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...
|
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...
|
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
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |