473,385 Members | 1,356 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,385 software developers and data experts.

Custom Navigation Controls Odd Behavior

On the form in question i have records from 5 related tables. In the footer of the form I have navigation controls (default navigation controls are turned off). When the form is launched, the navigation controls always appear disabled (grayed out). If I debug the code and put a break point where it enters the if conditions for the On Current event of the form and step through it, the navigation controls work fine. I do have a combobox on the form where the user can page through the records or type in characters of a customer they wish to view. Once a record is selected, the navigation controls work fine. Ideas?
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
  2.       If Me.CurrentRecord = 1 Then
  3.          Me.cmdPrevious.Enabled = False
  4.          Me.cmdFirst.Enabled = False
  5.       Else
  6.          Me.cmdPrevious.Enabled = True
  7.          Me.cmdFirst.Enabled = True
  8.       End If
  9.       If Me.CurrentRecord >= Me.Recordset.RecordCount Then
  10.          Me.cmdNext.Enabled = False
  11.          Me.cmdLast.Enabled = False
  12.       Else
  13.          Me.cmdNext.Enabled = True
  14.          Me.cmdLast.Enabled = True
  15.       End If
  16.  
Feb 8 '17 #1

✓ answered by jforbes

This actually makes sense. If it's on Record #1 and it thinks there are only 1 record(s), then
Expand|Select|Wrap|Line Numbers
  1. If Me.CurrentRecord >= Me.Recordset.RecordCount Then
will evaluate to True, disabling your fields.

You could try something like the following:
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
  2. Dim oClone As Recordset    
  3. Set oClone = Me.RecordsetClone
  4. oClone.MoveLast
  5.  
  6. If Me.CurrentRecord = 1 Then
  7.     Me.cmdPrevious.Enabled = False
  8.     Me.cmdFirst.Enabled = False
  9. Else
  10.     Me.cmdPrevious.Enabled = True
  11.     Me.cmdFirst.Enabled = True
  12. End If
  13. If Me.CurrentRecord >= oClone.RecordCount Then
  14.     Me.cmdNext.Enabled = False
  15.     Me.cmdLast.Enabled = False
  16. Else
  17.     Me.cmdNext.Enabled = True
  18.     Me.cmdLast.Enabled = True
  19. End If
This should make a copy of the Form's RecordSet and then move to it's end, somewhat forcing it to load completely, at least load completely into the Clone.

Lastly, this line will act differently depending on if you can Add records to your Form:
Expand|Select|Wrap|Line Numbers
  1. If Me.CurrentRecord >= Me.Recordset.RecordCount Then
The .CurrentRecord for the New Record will be the RecordCount + 1.
You may want to flip flop the If Statement:
Expand|Select|Wrap|Line Numbers
  1. If Me.CurrentRecord < oClone.RecordCount Then
  2. -or when new records can be added- 
  3. If Me.CurrentRecord <= oClone.RecordCount Then
  4.     Me.cmdNext.Enabled = True
  5.     Me.cmdLast.Enabled = True
  6. Else
  7.     Me.cmdNext.Enabled = False
  8.     Me.cmdLast.Enabled = False
  9. End If

7 990
PhilOfWalton
1,430 Expert 1GB
I use similar code, but hide the buttons again in the On Currant

Expand|Select|Wrap|Line Numbers
  1.     If Me.CurrentRecord = 1 Then
  2.         CmdPrevious.Visible = False
  3.     Else
  4.         CmdPrevious.Visible = True
  5.     End If
  6.  
  7.     If Me.CurrentRecord = Me.Recordset.RecordCount Then
  8.         Cmdnext.Visible = False
  9.     Else
  10.         Cmdnext.Visible = True
  11.     End If
  12.  
Can't see why your method won't work as there is very little difference. However on opening my form the next button is visible.

Phil
Feb 8 '17 #2
I can't explain what may be causing this. I thought it might be due to it taking too long to read records and report back but the table doesn't have very many records.
Feb 8 '17 #3
A bit of an update: If I enable Navigation Buttons in the form properties, my custom navigation buttons work as designed. Disabke Navigation Buttons in the form properties and my custom buttons fail when launching the form. Obviously I am missing something important here.
Feb 8 '17 #4
jforbes
1,107 Expert 1GB
Two things I can think of:
  • Comment out the Error Handling and see if you get an error. Access can get odd about Focus when disabling controls.
  • Put this code into your OnCurrent code: Debug.Print "CurrentRecord is " & Me.CurrentRecord & " out of " & Me.Recordset.RecordCount Then you can verify a little more of what is going on in the OnCurrent. You may want to put a debug.print for each branch of the IF statements.
Feb 9 '17 #5
I didn't get an error by commenting out the error handling. On the first entry into the event, debug.print shows 1 out of 1 records instead of showing 1 out of 10 records (currently there are 10 records in the table.) As long as the breakpoint at the entry of the event is active, the controls work as planned. Remove the breakpoint and it doesn't read the table.

In case this sheds a bit of light into what I'm doing. The tables being used on the form consist of a company table, city table, state table, company contact table and a company classification table. The company contact table is the many side of the company table. The company table is the many side of the city, state and classification tables. The record source for the form is a query with the three masters and the company table. The company contact table is in a subform by itself, has the parent and child fields set and is the only subform on the main form.
Feb 9 '17 #6
jforbes
1,107 Expert 1GB
This actually makes sense. If it's on Record #1 and it thinks there are only 1 record(s), then
Expand|Select|Wrap|Line Numbers
  1. If Me.CurrentRecord >= Me.Recordset.RecordCount Then
will evaluate to True, disabling your fields.

You could try something like the following:
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
  2. Dim oClone As Recordset    
  3. Set oClone = Me.RecordsetClone
  4. oClone.MoveLast
  5.  
  6. If Me.CurrentRecord = 1 Then
  7.     Me.cmdPrevious.Enabled = False
  8.     Me.cmdFirst.Enabled = False
  9. Else
  10.     Me.cmdPrevious.Enabled = True
  11.     Me.cmdFirst.Enabled = True
  12. End If
  13. If Me.CurrentRecord >= oClone.RecordCount Then
  14.     Me.cmdNext.Enabled = False
  15.     Me.cmdLast.Enabled = False
  16. Else
  17.     Me.cmdNext.Enabled = True
  18.     Me.cmdLast.Enabled = True
  19. End If
This should make a copy of the Form's RecordSet and then move to it's end, somewhat forcing it to load completely, at least load completely into the Clone.

Lastly, this line will act differently depending on if you can Add records to your Form:
Expand|Select|Wrap|Line Numbers
  1. If Me.CurrentRecord >= Me.Recordset.RecordCount Then
The .CurrentRecord for the New Record will be the RecordCount + 1.
You may want to flip flop the If Statement:
Expand|Select|Wrap|Line Numbers
  1. If Me.CurrentRecord < oClone.RecordCount Then
  2. -or when new records can be added- 
  3. If Me.CurrentRecord <= oClone.RecordCount Then
  4.     Me.cmdNext.Enabled = True
  5.     Me.cmdLast.Enabled = True
  6. Else
  7.     Me.cmdNext.Enabled = False
  8.     Me.cmdLast.Enabled = False
  9. End If
Feb 9 '17 #7
Thanks Jforbes... That took care of the problem. Appreciate the solution.
Feb 9 '17 #8

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

Similar topics

1
by: Robert Neville | last post by:
I am having some trouble with some old code revolving around custom form navigation buttons. My main form has a sub-form with these custom navigation buttons. In other words, the code should be...
1
by: Steven | last post by:
H I'm struggling to think this one through At run time I want to be able to read a layout HTML file from a database which includes tags for modules, e.g ...
0
by: Mark | last post by:
Hi, I am playing around with creating custom server controls for use within a ASP.NET page. I am creating a contact form and have the following question I am capturing the form postback data...
1
by: John Buchmann | last post by:
I'd like to get alot more knowledge on learning how to make custom server controls. All my asp.net books either don't mention it, or briefly discuss it. Does anyone know of a GOOD book on this...
0
by: Darren Carter | last post by:
I am trying to figure out how to create a static menu on a master page that has the top level navigation in a horizontal layout, and the corresponding second level of navigation on another...
3
by: Peter | last post by:
Hello, One thing I am looking to do is to create a couple of different custom Web Controls that can give me added options when specifying them in an ASP.NET page. For example: ...
2
by: davidwank | last post by:
Hi. Why is it practical to have the ASP.NET navigation controls based on XML? I would love to just use databinding and then be able to dynamically update the navgiation menu (e.g. for a ...
2
by: Dushyant | last post by:
Hi everyone, Actually I have recently started working with ASP.NET 2.0 and I have been working on the globalization aspect of my company's web project. At this moment, I am struck with...
4
by: Smokey Grindle | last post by:
What is the best way to write dynamic controls in ASP.NET 2.0?
2
by: munkee | last post by:
I use the following code to add the number of records in to my custom navigation within my access database. A simple "Cost x of y" in my sub form that allows me to add costs to a particular activity,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.