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

Another SetFocus Question - SetFocus from SubForm

675 512MB
This should be so, so simple I hesitate to ask.

I have a Form named "fNavButtons" used as a SubForm in control named "subformNavButtons". subformNavButtons is a control on my main form named "fAAA".

fNavButtons has 2 CommandButtons, cmdNextRec and cmdPrevRec. These are on a subform to allow an AutoRepeat to continue when form fAAA gets another record.

If I am at the first record, I want cmdPrevRec.Enabled = False, and if I am at the last record, cmdNextRec.Enabled = False. Otherwise the command buttons are .Enabled = True.

The problem is that with filters I can have one record, and therefore both need to be .Enabled = False. I can't seem to assign .Enabled = False for both simultaneously. This would mean the subform has no control enabled. I get run-time error 2164 - You can't disable a control while it has the focus on the 3rd line of the code below.
Expand|Select|Wrap|Line Numbers
  1. . . . 
  2. Forms!fAAA.SetFocus
  3. Forms!fAAA!txtTitleName.SetFocus
  4. Forms!fAAA!subformNavButtons.Form!cmdNextRec.Enabled = False
  5.  
The above lines of code should move the focus to the main form fAAA and set the focus to a textbox named "txtTitleName". This should allow line 4 of code to execute, as the subform does not have the focus. It is line 4 of code where the error occurs. "http://support.microsoft.com/kb/294212" says I'm doing the correctly, but I'm too close to it and cannot see my error.

If I remove the 4th line of code, the focus is actually at txtTitleName, and keyboard entries go to that control. Good, but I still have an enabled control that should be .Enabled = False
May 26 '07 #1
8 9740
MMcCarthy
14,534 Expert Mod 8TB
Have a look at this thread and see if it helps you out.

http://www.thescripts.com/forum/thread643047.html
May 26 '07 #2
nico5038
3,080 Expert 2GB
Hmm, why not add a << (First) and >> (Last) button that can be enabled always and ease the scrolling perhaps too ?

Nic;o)
May 26 '07 #3
OldBirdman
675 512MB
I saw this thread. I am trying to also create my own navigation buttons, but in this case only the "Next" and "Previous" buttons, not the First, Last, or NewRecord. I have no trouble writing this code.

These 2 command buttons are on a subform. This is to allow me to hold the buttons down, and have the AutoRepeat = True. This cannot be done if the buttons are on the form bound to a recordset. I can detect the first or last record, and set cmdNextRec.Enabled = True/False. Similarly with cmdPrevRec.
Expand|Select|Wrap|Line Numbers
  1. If boolStart Then 'I am at first record
  2.     cmdNextRec.SetFocus
  3.     cmdPrevRec.Enabled = False
  4. End If
  5. If BoolEnd Then 'I am at last record
  6.     cmdPrevRec.SetFocus
  7.     cmdNextRec.Enabled = False
  8. End If
  9.  
If I apply a filter that only has one record, so boolStart = True and boolEnd = True. The above code will fail because line 6 cannot SetFocus to a control that .Enabled = False. If I comment out line 6, line 7 fails because I cannot set .Enabled = False if the object has the focus.

There are no other controls on this subform to accept the focus. If I set the focus to a control on the main form, fAAA, I still cannot set both command buttons on the subform with .Enabled = False. Apparently the subform focus is independent of the main form. Although the main form receives the keystrokes, there must be something to have the focus if I return to the subform.

I would like the subform itself to have the focus if both commands are not enabled. But I cannot set the focus to the subform if any control on the subform can have the focus, and I cannot set enabled to False for both commands if the subform does not have the focus. Catch 22!
May 26 '07 #4
OldBirdman
675 512MB
Response to Nico:

Adding a cmdFirst and a cmdLast button makes no difference, they too would have to both be .Enabled = False. If I am at the last record, there should not be an enabled button that allows me to go to the last record or the first record. I'm already there.

I have this grevience against programs that have buttons that then give me a MsgBox telling me I can't do what the button says it does. MsgBox is to respond to an error that cannot be prevented, such as "Enter a number between 2 and 4" and the user enters a 5. Also, I don't like to push a button and have nothing happen. Makes me think the response is slow, or the computer is hung up somehow.

Not sure how two new buttons reduce scrolling.
May 26 '07 #5
nico5038
3,080 Expert 2GB
Well, when there are more than 2 records the First and Last button will effectively allow a user faster access to the last/first record.
The First and Last buttons never have to be disabled, as they are appropriate (however useless) when only one record has been found. It's however a solution to the problem that a form needs at least one active control that can hold the focus. The alternative would be a dummy control and I think that the First and Last buttons at least will add functionality to your subform :-)

Personally I never use a setup like this. I prefer to show the user all rows in a datasheet subform and have him use the right-click popup menu to filter the rows. Besides such a datasheet subform I offer a set of buttons with the basic actions like [Add], [Update], [Delete], [Print], etc.

Nic;o)
May 27 '07 #6
OldBirdman
675 512MB
I am going to close this thread. Access Help for SetFocus Method implies that the form can have the focus if there is no control able to have the focus. Apparently true only if there are no controls on the form when loaded.

I had tried to strip all extraneous information from the problem before I presented it to this forum. I think it is easier to understand a simple piece of code rather than seeing the entire program. Whether I should or should not have a Delete Command is not a part of the question. I am inferring from the answer that the answer is that I cannot do what I want.

Thank you for your time and thoughts in attempting to answer this question.

Old Birdman
May 30 '07 #7
FishVal
2,653 Expert 2GB
You are right thais is really too simple to ask.
Simply add the third control to your navigation subform. This can be for example blank option group without label which looks like frame and call SetFocus method for this control before disabling buttons.

Example of working code:

Private Sub btn1_Click()
Me.Frame2.SetFocus
Me.btn1.Enabled = False
End Sub

Private Sub btn2_Click()
Me.Frame2.SetFocus
Me.btn2.Enabled = False
End Sub

The form contains 3 controls: 2 buttons (btn1, btn2) placed in the frame of option group (Frame2). Click on the button disables it. All two buttons may be disabled without getting error message.

The problems with dummy control are the folowing:
1) not all controls can actually receive focus (e.g. Label, Image etc)
2) the control has to be visible to receive focus.

Option group frame control does fit these needs or you should use any custom control.

Good luck.
Jun 3 '07 #8
OldBirdman
675 512MB
This is a very interesting solution.

Although Access won't let me set the focus to a control with .Visible = False, it will allow a frame to get the focus, even if that frame has no controls (option buttons, check boxes, or toggle buttons) within it. Furthermore, it will allow .BorderStyle = Transparent, making it not visible.

I can find no unpredictable or unacceptable results to this solution. Nothing is highlighted, there is no indication about which control has the focus. Random mouse clicks in the vicinity of the invisible control will eventually hit this control, but Access responds as if the form itself were selected.

Don't know why I didn't think of this. I just knew that there was a SIMPLE solution out there somewhere.

Thank you for your solution.

OldBirdman
Jun 7 '07 #9

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

Similar topics

1
by: David | last post by:
Hi, I have a form which requires Serial Numbers to be loaded from another form. When I press a button, another form opens with a list of Serial Numbers. I have the record selectors enabled. ...
1
by: John Phelan-Cummings | last post by:
I'm not certain if this made the post. Sorry if it's a repeat: Using a Button to take an autonumber from one form to populate another autonumber field on another form. I have a Mainform "A"...
1
by: BartonConstruction | last post by:
Greetings all, I have a main form (frmClients) with two subforms (subVisits) (subAccount). I got the subforms to reflect what the main form is showing by linking master and child fields (I...
1
by: John Ortt | last post by:
Can anyone think of a way of doing this? I have a readonly subform with no active controls but I want to activate the control box rather than have a field in the next subform activate. Thanks...
12
by: Michael R | last post by:
TabCtrl --- ..............Tab1--Subform1 ..............Tab2--Subform2---TabCtrl2---Tab21 ..........................................................---Tab22...
7
by: Hong | last post by:
Hi I have a main form with 7 subforms where the master/child link is the RefID in the main form where the Main form is 1-many relationship to those subforms. All the subform have the same...
8
by: freeskier | last post by:
I have been using the following code to cycle through a subform and disable all textboxes on a form. If a textbox on the form has the focus when this is run I get error "can't disable a control when...
3
by: ckrows | last post by:
I have a main form with a button that makes a subform visible. I added a button in the form footer of the subform that is supposed to hide the subform. This does not work because the focus is on...
18
by: Marilyth | last post by:
I am using Windows XP and Access 2003. I have searched through my HUGE book & the questions here, and found some items that "might" help, but unsure still. I am still getting versed on Access. I...
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
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.