473,497 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SelTop query

6 New Member
Hi

I am using Access 2003 - any help very much appreciated, I seem to be going nowhere with this!!!

I am using Stephen Lebans Seltop code to hold the cursor position after requery. I have 2 continuous subforms (Child 143 and Shifts Allocate)embedded into the main form (Shifts NP), the SelTop code runs ok on the Top form but always fails on the top row of the Second form (runtime error 2101)... but only if the top row is the first row to be edited, subsequently it works fine? I have noted below where the code fails. [** moderator edit: see line 119 **]

Thanks MM


Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. ' Our class to hold a couple of Public vars
  4. Private SR As clsSetRow
  5. Dim Ins As Boolean
  6.  
  7.  
  8. Sub CLOSE_BUTTON_Click()
  9. On Error GoTo Err_CLOSE_BUTTON_Click
  10.  
  11.  
  12.     DoCmd.CLOSE
  13.  
  14. Exit_CLOSE_BUTTON_Click:
  15.     Exit Sub
  16.  
  17. Err_CLOSE_BUTTON_Click:
  18.     MsgBox Err.DESCRIPTION
  19.     Resume Exit_CLOSE_BUTTON_Click
  20.  
  21. End Sub
  22.  
  23. Sub Combo51_AfterUpdate()
  24.     ' Find the record that matches the control.
  25.     Me.RecordsetClone.FindFirst "[W/E] = '" & Me![Combo51] & "'"
  26.     Me.Bookmark = Me.RecordsetClone.Bookmark
  27. End Sub
  28.  
  29. Private Sub EMPLOYEE_ID_BeforeUpdate(Cancel As Integer)
  30.     Combo96.SetFocus
  31. End Sub
  32.  
  33. Private Sub CLIENT_INVOICE_ID_AfterUpdate()
  34. DoCmd.RunCommand acCmdRefresh
  35. End Sub
  36.  
  37.  
  38. Private Sub Combo96_BeforeUpdate(Cancel As Integer)
  39. DoCmd.SetWarnings (False)
  40.  
  41.     Dim stDocName As String
  42.     Dim stLinkCriteria As String
  43.     Dim rsc As DAO.Recordset
  44.  
  45.     Set rsc = Me.RecordsetClone
  46.  
  47.     stLinkCriteria = "[Combo96]=" & "'" & "[EMPLOYEE ID], QSHIFT3" & "'"
  48.  
  49.         'Check QSHIFT2 query for duplicate Employee
  50.  
  51.     DoCmd.SetWarnings (True)
  52.     Set rsc = Nothing
  53.  
  54.     If (DLookup("[Employee ID]", "QSHIFT3", "[EMPLOYEE ID]= '" & Me![Combo96] & "' AND (((#" & Me![FROM] & "#>=[FROM TIME]AND #" & Me![FROM] & "#<[TO TIME])OR (#" & Me![TO] & "#>[FROM TIME]AND #" & Me![TO] & "#<=[TO TIME]))OR ((#" & Me![FROM] & "#<[FROM TIME]AND #" & Me![TO] & "#>[TO TIME])))AND [W/E]=#" & Format(Me![W/E], "mm/dd/yy") & "# AND [X6]='" & Me![X6] & "'")) > 0 Then
  55.  
  56.         'Undo duplicate entry Removed BY MM - Me.Undo
  57.  
  58.         'Message box warning of duplication
  59.         MsgBox "Warning Employee is already working.", vbCritical
  60.         Exit Sub
  61.     End If
  62.  
  63. End Sub
  64.  
  65. Private Sub Form_AfterInsert()
  66.   Ins = False
  67.  
  68. End Sub
  69.  
  70.  
  71. Private Sub Form_AfterUpdate()
  72.  
  73. Dim OrigSelTop As Long
  74. Dim RowsFromTop As Long
  75. Dim OrigCurrentSectionTop As Long
  76.  
  77. ' Must cache the current props because Requery will
  78. ' reset them
  79. OrigSelTop = SR.SelTop
  80. OrigCurrentSectionTop = SR.CurrentSectionTop
  81.  
  82. ' Turn off screen redraw
  83. Me.Painting = False
  84.  
  85. ' Requery the Form
  86. Forms![shifts np].[Child143].Form.Requery
  87. Forms![shifts np].[shifts allocate].Form.Requery
  88.  
  89. ' Calculate how many rows, if any, the selected
  90. ' row was from the top prior to the Requery
  91.  
  92. ' Check if Section Top = 0
  93.  
  94.     If OrigCurrentSectionTop = 0 Then
  95.  
  96.     Forms![shifts np].[Child143].Form.Requery
  97.     Forms![shifts np].[shifts allocate].Form.Requery
  98.     Me.Painting = True
  99.     Else
  100.  
  101.     RowsFromTop = (OrigCurrentSectionTop - Me.Section(acHeader).Height) / Me.Section(acDetail).Height
  102.  
  103.     End If
  104.  
  105. ' Setting the SelTop property forces this row to appear
  106. ' at the top of the Form. We will subtract the number of rows
  107. ' required, if any, so that the original current row remains
  108. ' at the original position prior to the Requery.
  109. ' First set the current record to the last record.
  110. ' This is required due to the method that
  111. ' that the Access GUI manages the ScrollBar.
  112.  
  113. If Me.RecordsetClone.RecordCount = 0 Then
  114.  
  115. Forms![shifts np].[Child143].SetFocus 'sets the focus to "shifts Allocate"
  116.  
  117. Else
  118. Me.SelTop = Me.RecordsetClone.RecordCount
  119. CODE FAILS HERE
  120. Me.SelTop = OrigSelTop - RowsFromTop 
  121. DoEvents
  122. Me.Painting = True
  123. ' Now setfocus back to the original row prior to the Requery
  124. Me.RecordsetClone.AbsolutePosition = Me.CurrentRecord + RowsFromTop - 1
  125. Me.Bookmark = Me.RecordsetClone.Bookmark
  126. End If
  127.  
  128. If (DLookup("[CLIENT INVOICE ID]", "[Contracted Hours Query3]", "[CLIENT INVOICE ID]") = Me![CLIENT INVOICE ID]) And (DLookup("[WARNING]", "[Contracted Hours Query3]", "[WARNING]") = -1) Then
  129.     MsgBox "Hours Exceed Contract, Authorisation Required", vbCritical + vbOKCancel, "Contract Check"
  130.     Exit Sub
  131. End If
  132.  
  133. End Sub
  134.  
  135.  
  136.  
  137. Private Sub Form_BeforeInsert(Cancel As Integer)
  138.     Ins = True
  139. End Sub
  140.  
  141. Private Sub Form_BeforeUpdate(Cancel As Integer)
  142. ' Display a message that says employee already working.
  143. DoCmd.SetWarnings (False)
  144.  
  145.   If IsNull(Me![EMPLOYEE ID]) Or Me![EMPLOYEE ID] = "" Then
  146.     MsgBox "PLEASE ENTER EMPLOYEE ID", vbExclamation
  147.     DoCmd.CancelEvent
  148.     Exit Sub
  149.   End If
  150.  
  151.   If IsNull(Me![W/E]) Or Me![W/E] = "" Then
  152.     MsgBox "PLEASE ENTER W/E DATE", vbExclamation
  153.     DoCmd.CancelEvent
  154.     Exit Sub
  155.   End If
  156.  
  157.   If IsNull(Me![DATE1]) Or Me![DATE1] = "" Then
  158.     MsgBox "PLEASE ENTER THE DATE", vbExclamation
  159.     DoCmd.CancelEvent
  160.     Exit Sub
  161.   End If
  162.  
  163.   If IsNull(Me![CLIENT INVOICE ID]) Or Me![CLIENT INVOICE ID] = "" Then
  164.     MsgBox "PLEASE ENTER THE CLIENT ID", vbExclamation
  165.     DoCmd.CancelEvent
  166.     Exit Sub
  167.   End If
  168.  
  169.   If IsNull(Me![DESCRIPTION]) Or Me![DESCRIPTION] = "" Then
  170.     MsgBox "PLEASE ENTER THE JOB DESCRIPTION", vbExclamation
  171.     DoCmd.CancelEvent
  172.     Exit Sub
  173.   End If
  174.  
  175.   If IsNull(Me![FROM TIME]) Or Me![FROM TIME] = "" Then
  176.     MsgBox "PLEASE ENTER THE START TIME", vbExclamation
  177.     DoCmd.CancelEvent
  178.     Exit Sub
  179.   End If
  180.  
  181.   If IsNull(Me![TO TIME]) Or Me![TO TIME] = "" Then
  182.     MsgBox "PLEASE ENTER THE FINISH TIME", vbExclamation
  183.     DoCmd.CancelEvent
  184.     Exit Sub
  185.   End If
  186.  
  187. If ([Student Visa] = -1) = True Then
  188.     MsgBox "Employee is working on a Student Visa - please check weekly shifts do not exceed 20 hours", vbCritical + vbOKCancel, "Employee Visa Check"
  189.   End If
  190.  
  191.   If ([HOURS] > 12) = True Then
  192.     MsgBox "Hours for this shift exceed 12 ...  please confirm", vbCritical + vbOKCancel, "Hours check"
  193.   End If
  194.  
  195. If (DLookup("[CLIENT INVOICE ID]", "[ENR QUERY]", "[CLIENT INVOICE ID]") = (Me![CLIENT INVOICE ID])) And (DLookup("[enr1]", "[enr query]", "[enr1]") = (Me![Combo96])) Or (DLookup("[enr2]", "[enr query]", "[enr2]") = (Me![Combo96])) Or (DLookup("[enr3]", "[enr query]", "[enr3]") = (Me![Combo96])) Or (DLookup("[enr4]", "[enr query]", "[enr4]") = (Me![Combo96])) Or (DLookup("[enr5]", "[enr query]", "[enr5]") = (Me![Combo96])) Or (DLookup("[enr6]", "[enr query]", "[enr6]") = (Me![Combo96])) Or (DLookup("[enr7]", "[enr query]", "[enr7]") = (Me![Combo96])) Or (DLookup("[enr8]", "[enr query]", "[enr8]") = (Me![Combo96])) Or (DLookup("[enr9]", "[enr query]", "[enr9]") = (Me![Combo96])) Or (DLookup("[enr10]", "[enr query]", "[enr10]") = (Me![Combo96])) And Ins = True Then
  196.     MsgBox "Employee not required by this Client", vbCritical + vbOKCancel, "Employee Status Check"
  197.     DoCmd.CancelEvent
  198.     Combo96.SetFocus
  199.     Exit Sub
  200.   End If
  201.  
  202. End Sub
  203.  
  204.  
  205.  
  206.  
  207. Private Sub Form_Current()
  208.  
  209. If Not SR Is Nothing Then
  210.     SR.SelTop = Me.SelTop
  211.     SR.CurrentSectionTop = Me.CurrentSectionTop
  212. End If
  213.  
  214.     If ([T/SHT] = "SENT") Or ([T/SHT] = "INV") Then
  215.     Me.AllowEdits = False
  216.   Else
  217.     Me.AllowEdits = True
  218.   End If
  219.  
  220.   DoCmd.RunCommand acCmdRefresh
  221.  
  222. End Sub
  223.  
  224. Private Sub Command141_Click()
  225. On Error GoTo Err_Command141_Click
  226.  
  227.  
  228.     DoCmd.CLOSE
  229.  
  230. Exit_Command141_Click:
  231.     Exit Sub
  232.  
  233. Err_Command141_Click:
  234.     MsgBox Err.DESCRIPTION
  235.     Resume Exit_Command141_Click
  236.  
  237. End Sub
  238. Private Sub Combo154_AfterUpdate()
  239.     ' Find the record that matches the control.
  240.     Dim RS As Object
  241.  
  242.     Set RS = Me.Recordset.Clone
  243.     RS.FindFirst "[W/E] = #" & Format(Me![Combo154], "mm\/dd\/yyyy") & "#"
  244.     If Not RS.EOF Then Me.Bookmark = RS.Bookmark
  245. End Sub
  246.  
  247.  
  248.  
  249. Private Sub Form_Load()
  250. Set SR = New clsSetRow
  251. End Sub
  252.  
  253. Private Sub Form_Open(Cancel As Integer)
  254.  
  255.   DoCmd.RunMacro "Homecare Ceased Macro"
  256.  
  257. End Sub
  258.  
  259. Private Sub JOB_CODE_Label_DblClick(Cancel As Integer)
  260. Forms![shifts np].Form.OrderBy = "[Description]"
  261. Forms![shifts np].Form.OrderByOn = True
  262.  
  263. End Sub
Jul 24 '11 #1
4 4921
nico5038
3,080 Recognized Expert Specialist
Much code, I would start with placing a break point (Click in the left ruler to get a brown dot) just before the error and continue there with F8 to single step through the statements. This will enable you to inspect the values of the variables (hover with your mouse pointer over the field). I expect that the calculation gives a negative value, but test and see.

Nic;o)
Jul 25 '11 #2
NeoPa
32,556 Recognized Expert Moderator MVP
For more on Debugging in VBA follow this link.
Jul 25 '11 #3
Mandy Medcraft
6 New Member
Hi Nic

Thanks for your response. I've tested the values when I run the code from different row positions and get the following:

On the top subform for which runs ok

OriginalSelTop, RowsfromTop, OrigCurrentSectionTop
Row1 1 0 1380
Row2 2 1 1680
Row3 3 2 1980
Row4 4 3 2280

But from the lower subform, which falls over
Row1 1 10 3345
Row2 2 1 600
Row3 3 2 900
Row4 4 3 1200

I cannot prove that it returns to 1 0 300 for the first row after editing elsewhere because I have to reset the form after debug, so I am never able to view the values on the second edit, but I assume that it returns to 1 0 300 after the code has run from another row, because it only ever falls over if i requery from Row1 first.

Probably not explaining this terribly well,but would really appreciate it if anyone could help. I am using Ver 7 Stephen Lebans SetGetScrollbars and it all works great except for this random value.

Many thanks
Mandy
Aug 17 '11 #4
nico5038
3,080 Recognized Expert Specialist
Looks like an initialization problem in the code to me. Somewhere the RowsFromTop and OrigSelTop isn't reset when starting again.

The "blunt" solution is to change your code from:
Expand|Select|Wrap|Line Numbers
  1. Me.SelTop = OrigSelTop - RowsFromTop 
  2.  
too:
Expand|Select|Wrap|Line Numbers
  1. if me.OrigSelTop = 1 then
  2.    Me.Seltop = 0
  3. else
  4.    Me.SelTop = OrigSelTop - RowsFromTop 
  5. endif
  6.  
But basically the subtraction could be changed into:
Expand|Select|Wrap|Line Numbers
  1. Me.SelTop = OriginalSelTop - 1
  2.  
As that's the netto effect as far as I can see from your dumped data.

Nic;o)
Aug 19 '11 #5

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

Similar topics

2
3410
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
9
3105
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
5368
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
14
3846
by: Dave Thomas | last post by:
If I have a table set up like this: Name | VARCHAR Email | VARCHAR Age | TINYINT | NULL (Default: NULL) And I want the user to enter his or her name, email, and age - but AGE is optional. ...
2
3980
by: TD | last post by:
I have a main form with a subform. On the main form is a button to apply/unapply a filter to show only certain records. On the main form is another button thats opens a form that shows the details...
0
3482
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
15
4383
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows...
6
4812
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
3
3629
by: Bill Hutchison | last post by:
I have a query that returns different results (3508 rows for snapshot, 6288 for dynaset) and that is the only thing I change to get the different results. When I try to make a table from the...
3
2541
by: pbd22 | last post by:
Hi. I need some help with structuring my query strings. I have a form with a search bar and some links. Each link is a search type (such as "community"). The HREF for the link's anchor looks...
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6881
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
7375
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
5456
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,...
1
4899
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...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.