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

Set Focus Problems in Navigationform...

7
Please help,

I have a navigation form with 2 top tab's. The left tab (Log In) is visible and has the focus on if the database opens. The tab contains only 2 text boxes for the username and password and has no left side tabs. The other top tab (Job Bag) has 5 left side tabs and is invisible. The user logs in and the right side tab on the top becomes visible. I search for more than a week and cant get it done that I can set the focus on one of the left side tabs on the right top tab. I get the focus changed to the right side tab, but I don't get the focus on one of the left side tabs.

The line below sets the focus on the right tab (Job Bag), but I cant finish the next level to get the focus and view on one of the left side tabs.

Expand|Select|Wrap|Line Numbers
  1. Forms!NavigationForm!tabJobEntry.SetFocus


I know this subject is discussed in many places and I tried by myself, but I can't get it done and any help would be really appreciated.


Attached Images
File Type: jpg DatabasePic.jpg (26.3 KB, 1644 views)
Sep 30 '14 #1
14 3942
zmbd
5,501 Expert Mod 4TB
ACC2010 and newer navigation controls (navctrl) are a love hate tool.
I love the ease, I like the fact that the forms late load, and that they load fresh each time, I hate the reference methods.

You must keep in mind, these are NOT tab control forms.
Very little of what you have learned about tab control forms is applicable to the navcltrl.

I have a similar two-tiered navctrl.button grouping and I often need to move between the second tier or from the tier1 group1 to the tier group2 buttons.
This is most likely the best route for what you want.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.BrowseTo _
  2.    objecttype:=acBrowseToForm, _
  3.    objectname:="Name_of_Form_Bound_to_NavCtrlButton", _
  4.    PathtoSubformControl:="frm_navigation.navigationsubform" 
  5.  ', WhereCondition:="RecordsetField = " & [inthiscasenumeric]
  6.  
Change Line 3 to the name of the form that your navctrl.button("Job Overview") loads

Line 4, you will have to change the names to the parent and child names. I used the default navctrl.subformctrl name of "navigationsubform" this is the container that the navctrl loads your actual subform in.

I commented out the wherecondtion; however, that works just like any of the form filters and is a handy way to pass information between the currently loaded form and the one to load... keep in mind, this sets the filter on the form to be loaded!
Let’s say I’ve just loaded the form so I'm in [Tier1(button1):Tier2(button1)] and I need to go to the [Tier1(button3):Tier2(button4)], if the form named “sfm_T1B3T2B4” is associated with this navctrl.button, then this is how the above would work

Expand|Select|Wrap|Line Numbers
  1. DoCmd.BrowseTo _
  2.    objecttype:=acBrowseToForm, _
  3.    objectname:=" sfm_T1B3T2B4", _
  4.    PathtoSubformControl:="frm_navigation.navigationsubform"
  5.  
And the [tier1 button 3, tier 2 button4] would be selected.
Sep 30 '14 #2
sapo73
7
Hi zmbd,

I took the code you suggested and changed to:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.BrowseTo _
  2.       objecttype:=acBrowseToForm, _
  3.       objectname:="frmJobOverview", _
  4.       PathtoSubformControl:="NavigationForm.NavigationSubform"
It does not go thru. The right top tab is selected, but the desired left side tab is not and the form wont open. It is almost the same as I got with the line from my first post.

Do I need a indication for the top tab and the left tab?
Sep 30 '14 #3
twinnyfo
3,653 Expert Mod 2GB
Z,

ACC2010 and newer navigation controls (navctrl) are a love hate tool
Do you have any history or intuition on why MS would give us such a lovely tool that is so difficult to use? It's like installing new anti-lock brakes on a car, but they only work when your left turn signal is on and your radio is tuned to 87.5. Yeah, they'll work but it takes some practice.

I hesitate to incorporate the Nav Controls because of hte non-stop problems I see people having with them. I'd just like to know if you've heard anything about "why"?
Sep 30 '14 #4
zmbd
5,501 Expert Mod 4TB
Tier one will mean the top, main group of navctrl.buttons
Tier two will mean any buttons that are linked to the top row of navctrl.buttons


Open the form containing the navigation control in design mode.
Select the first tier button that contains your second tier button group
Right click on the second tier button that you want to have selected and show properties.
All tab
Forth property, [Navigation Target Name]
This is the name that you need to place in line 3.
Sep 30 '14 #5
sapo73
7
Hi zmbd,

this is exactly what I did. See the attachment. It still just selects the right tab and is not displaying all left tabs. It looks like kind of corrupted, only the top first button appears, all others are missing and the form is not displayed, it stays on the log in form from the left top tab.

Isn't there a way to go with .setfocus as I tried in the first post? Is the DoCmd the only way?

Attached Images
File Type: jpg 2014_10_01_AccessPropertySheet.jpg (62.8 KB, 1617 views)
Oct 1 '14 #6
zmbd
5,501 Expert Mod 4TB
The docmd.browse is the only method to trip the navctrl.control actions.

You must have ALL of the subforms saved and CLOSED before opening the form with the navctrl

Please post your revised vba code behind the call...
actually lets see the entire code block around the docmd.
You should do a compile and fix any errors as described before you post the code following the recomendations here:[*]> Before Posting (VBA or SQL) Code.

Also, from your picture I cannot tell what the name of the navigation target is, please post that information as well.
Oct 1 '14 #7
sapo73
7
Hi zmbd,

can you give me a mail address that I could send you the entire database? Sascha
Oct 1 '14 #8
zmbd
5,501 Expert Mod 4TB
No need to send the database yet, besides I would not be able to open the database at work as we have a secured IT environment (makes visiting image and file dump sites (that's right, no google drive for me!) impossible etc...). (-_-)

Please provide the information I have requested.
The code block
and the value from the [navigation target] property of the navctrl.button you wish to navigate to.
Oct 1 '14 #9
sapo73
7
Hi zmbd,

the code is on the Log In form of my database and suppose to switch to the desire form after log in. See below code and the navigation target of the form I like to open.

Navigation Target: frmJobOverview

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub Form_Open(Cancel As Integer)
  5.     txtPassword.SetFocus
  6. End Sub
  7.  
  8. Private Sub txtPassword_AfterUpdate()                                       ' Username and password verification
  9.  
  10. ' Use DAO database to look up user and verify password
  11. ' to allow tabs and menues as per setting in tbl Users
  12.  
  13.     On Error GoTo errorHandler
  14.  
  15.     Dim dbs As DAO.Database
  16.     Dim rstUser As DAO.Recordset
  17.     Dim strPassword As String
  18.     Dim strUserName As String
  19.     Dim strEntPass As String
  20.  
  21.     strUserName = IIf(IsNull(Me.txtUserName), "", Me.txtUserName)
  22.     strEntPass = IIf(IsNull(Me.txtPassword), "", Me.txtPassword)
  23.  
  24.     If strUserName = "" Then                                                    ' In case of empty username
  25.         Me.txtUserName.SetFocus
  26.         Me.txtPassword.Value = ""
  27.         Exit Sub
  28.     End If
  29.  
  30.     Set dbs = CurrentDb
  31.     Set rstUser = dbs.OpenRecordset("tblEmployee", dbOpenDynaset)
  32.  
  33.     rstUser.FindFirst "[EmployeeLogIn] = '" & strUserName & "'"
  34.  
  35.     If rstUser.NoMatch Then                                                     ' In case user is not set up
  36.         MsgBox "User is not available...please log on with other name!"
  37.         Me.txtUserName.Value = ""
  38.         Me.txtPassword.Value = ""
  39.         Me.txtPassword.SetFocus
  40.         Me.txtUserName.SetFocus
  41.     Else
  42.         strPassword = rstUser!EmployeePassword                                  ' If available, get password and user level
  43.         gBytUserLevel = rstUser!EmployeeUserLevel
  44.         gBytDepartment = rstUser!DepartmentID
  45.     End If
  46.  
  47.     If strEntPass = strPassword And gBytUserLevel = 1 Then                      ' User level 1, all tabs visible
  48.  
  49.         gStrUserName = strUserName
  50.  
  51.         Forms!NavigationForm.tabLogIn.Caption = "Log Out"
  52.         Forms!NavigationForm.tabJobEntry.Enabled = True
  53.         Forms!NavigationForm.tabPlanning.Enabled = True
  54.         Forms!NavigationForm.tabScheduling.Enabled = True
  55.         Forms!NavigationForm.tabReporting.Enabled = True
  56.         Forms!NavigationForm.tabSetting.Enabled = True
  57.         Forms!NavigationForm.tabJobEntry.Visible = True
  58.         Forms!NavigationForm.tabPlanning.Visible = True
  59.         Forms!NavigationForm.tabScheduling.Visible = True
  60.         Forms!NavigationForm.tabReporting.Visible = True
  61.         Forms!NavigationForm.tabSetting.Visible = True
  62.  
  63.  
  64.     ElseIf strEntPass = strPassword And gBytUserLevel = 2 Then                  ' User level 2, settings off
  65.  
  66.         gStrUserName = strUserName
  67.  
  68.         Forms!NavigationForm.tabLogIn.Caption = "Log Out"
  69.         Forms!NavigationForm.tabJobEntry.Visible = True
  70.         Forms!NavigationForm.tabPlanning.Visible = False
  71.         Forms!NavigationForm.tabScheduling.Visible = False
  72.         Forms!NavigationForm.tabReporting.Visible = False
  73.         Forms!NavigationForm.tabJobEntry.Enabled = True
  74.         Forms!NavigationForm.tabPlanning.Enabled = False
  75.         Forms!NavigationForm.tabScheduling.Enabled = False
  76.         Forms!NavigationForm.tabReporting.Enabled = False
  77.         Forms!NavigationForm.tabSetting.Visible = False
  78.  
  79.         DoCmd.BrowseTo _
  80.         objecttype:=acBrowseToForm, _
  81.         objectname:="frmJobOverview", _
  82.         PathtoSubformControl:="NavigationForm.NavigationSubform"
  83.  
  84.     ElseIf strEntPass = strPassword And gBytUserLevel = 3 Then                  ' User level 3, settings, reporting, etc off
  85.  
  86.         gStrUserName = strUserName
  87.  
  88.         Forms!NavigationForm.tabLogIn.Caption = "Log Out"
  89.         Forms!NavigationForm.tabJobEntry.Visible = True
  90.         Forms!NavigationForm.tabPlanning.Visible = False
  91.         Forms!NavigationForm.tabScheduling.Visible = False
  92.         Forms!NavigationForm.tabReporting.Visible = False
  93.         Forms!NavigationForm.tabJobEntry.Enabled = True
  94.         Forms!NavigationForm.tabPlanning.Enabled = False
  95.         Forms!NavigationForm.tabScheduling.Enabled = False
  96.         Forms!NavigationForm.tabReporting.Enabled = False
  97.         Forms!NavigationForm.tabSetting.Visible = False
  98.  
  99.     Else
  100.  
  101.         Me.txtUserName.Value = ""
  102.         Me.txtPassword.Value = ""
  103.  
  104.     End If
  105.  
  106.     'Call currentUserName(strUserName)                                           ' Store the log in name in function
  107.  
  108.     rstUser.Close
  109.     dbs.Close
  110.  
  111.     Set rstUser = Nothing
  112.     Set dbs = Nothing
  113.  
  114.     Exit Sub
  115.  
  116. errorHandler:
  117.  
  118.     MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
  119.  
  120. End Sub
Oct 2 '14 #10
zmbd
5,501 Expert Mod 4TB
Just a quick view, the lab was filled with Gremlins... wish someone would quit pouring water on them, anyway, I've the kids to feed so a quick pop in and the youngest is helping me type so forgive the typos :P


I would think that Lines 79 thru 82 should go after the if..then..else-if structure... around line 105 (I prefer the select...case structure instead of the if/the/else-if stack, just me (^_^))
If the buttons are not enabled at the time of call for the browse to command, there can be some goofiness.

Place a STOP at line 40 and execute the form.
Once the code breaks to debug mode, [f8] to step thru the code and make sure that the entire code is executing as expected. If possible arrange things so that you can see both the form and the code at the same time. I have a dual monitor that makes this easy so that I can have the vbe open and the database gui open at the same time. Often, computers will come with a graphics card that most people use and then there's a legacy VGA port ... two tuners... two monitors and WinXP and newer can take advantage of both ports. I highly advise it if you have a spare monitor and the real-estate.

STEP THIS SLOWLY... if we're looking at a timing issue, which can happen when the code runs at full speed, the human touch may slow things down enough that the flags get set and updated before the command to browse to the form is called. Been many a time for me that the code works as expected in [F8] but not at full tilt - solution is simple, loop until flag state shows correctly (and I usually place a trouble counter too to prevent infinite loops).

> " frmJobOverview " > Just double checking, this is the copy and paste directly from the control property window... or did you type it into the post. Please be patient with me asking this question, it's vital to the overall solution.
Oct 2 '14 #11
sapo73
7
Sorry for the late reply, but we had holidays here in Saudi Arabia and I did not touch my computer for a couple days.

I did as you suggested and put it in select case form. I added a function to pause the code with 3 or 5 seconds before the docmd part. It is ending up exactly the same as before. I wend thru each line in debug mode and could not see any flaw. See the attached pic, this is how the desired form opens. Only 2 items are visible on the left side and one of them looks even kind of corrupted or defective and the top one is still from the previous form "Log In". If I hover over the other tabs, they become visible. Maybe this description is helpful for you...I copied and pasted the navigation target and check already multiple times for correctness.

Attached Images
File Type: jpg Untitled.jpg (11.8 KB, 1384 views)
Oct 7 '14 #12
zmbd
5,501 Expert Mod 4TB
That's OK, I understand, Our Holidays/Holy Days are important to recharge the mind, the body, the sprit and our relationship with God. (^_^) At times it would be nice if the US would allow such days in each faith to be observed as days away from work. However, with the number of different faiths we have it would make running a business very difficult.

Anyway I digress:

Lets add one more line of code,
Right before the DoCmd.BrowseTo
insert Forms!NavigationForm.Repaint

This should update your form's GUI.

Otherwise, Please post your newest code and I'll run it thru my test data base later this afternoon. I have a meeting this morning that will eat-up a lot of my day... nice break from the routine; however, it puts me behind for the day.
Oct 7 '14 #13
sapo73
7
I tried with the repaint and it ends up exactly as without. Here is the current code also. I get the feeling that the database might be corrupted or defective somehow.

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtPassword_AfterUpdate()                                       ' Username and password verification
  2.  
  3. ' Use DAO database to look up user and verify password
  4. ' to allow tabs and menues as per setting in tbl Users
  5.  
  6.     On Error GoTo errorHandler
  7.  
  8.     Dim dbs As DAO.Database
  9.     Dim rstUser As DAO.Recordset
  10.     Dim strPassword As String
  11.     Dim strUserName As String
  12.     Dim strEntPass As String
  13.  
  14.     strUserName = IIf(IsNull(Me.txtUserName), "", Me.txtUserName)
  15.     strEntPass = IIf(IsNull(Me.txtPassword), "", Me.txtPassword)
  16.  
  17.     If strUserName = "" Then                                                    ' In case of empty username
  18.         Me.txtUserName.SetFocus
  19.         Me.txtPassword.Value = ""
  20.         Exit Sub
  21.     End If
  22.  
  23.     Set dbs = CurrentDb
  24.     Set rstUser = dbs.OpenRecordset("tblEmployee", dbOpenDynaset)
  25.  
  26.     rstUser.FindFirst "[EmployeeLogIn] = '" & strUserName & "'"
  27.  
  28.     If rstUser.NoMatch Then                                                     ' In case user is not set up
  29.         MsgBox "User is not available...please log on with other name!"
  30.         Me.txtUserName.Value = ""
  31.         Me.txtPassword.Value = ""
  32.         Me.txtPassword.SetFocus
  33.         Me.txtUserName.SetFocus
  34.     Else
  35.         strPassword = rstUser!EmployeePassword                                  ' If available, get password and user level
  36.         gBytDepartment = rstUser!DepartmentID
  37.         gBytUserLevel = rstUser!EmployeeUserLevel
  38.     End If
  39.  
  40.     Select Case gBytUserLevel
  41.  
  42.         Case 1 And strEntPass = strPassword                                     ' User level 1, all tabs visible
  43.  
  44.             gStrUserName = strUserName
  45.  
  46.             Forms!NavigationForm.tabLogIn.Caption = "Log Out"
  47.             Forms!NavigationForm.tabJobEntry.Enabled = True
  48.             Forms!NavigationForm.tabPlanning.Enabled = True
  49.             Forms!NavigationForm.tabScheduling.Enabled = True
  50.             Forms!NavigationForm.tabReporting.Enabled = True
  51.             Forms!NavigationForm.tabSetting.Enabled = True
  52.             Forms!NavigationForm.tabJobEntry.Visible = True
  53.             Forms!NavigationForm.tabPlanning.Visible = True
  54.             Forms!NavigationForm.tabScheduling.Visible = True
  55.             Forms!NavigationForm.tabReporting.Visible = True
  56.             Forms!NavigationForm.tabSetting.Visible = True
  57.  
  58.  
  59.     Case 2 And strEntPass = strPassword                                         ' User level 2, settings off
  60.  
  61.             gStrUserName = strUserName
  62.  
  63.             Forms!NavigationForm.tabLogIn.Caption = "Log Out"
  64.             Forms!NavigationForm.tabJobEntry.Visible = True
  65.             Forms!NavigationForm.tabPlanning.Visible = False
  66.             Forms!NavigationForm.tabScheduling.Visible = False
  67.             Forms!NavigationForm.tabReporting.Visible = False
  68.             Forms!NavigationForm.tabJobEntry.Enabled = True
  69.             Forms!NavigationForm.tabPlanning.Enabled = False
  70.             Forms!NavigationForm.tabScheduling.Enabled = False
  71.             Forms!NavigationForm.tabReporting.Enabled = False
  72.             Forms!NavigationForm.tabSetting.Visible = False
  73.  
  74.     Case 3 And strEntPass = strPassword                                         ' User level 3, settings, reporting, etc off
  75.  
  76.             gStrUserName = strUserName
  77.  
  78.             Forms!NavigationForm.tabLogIn.Caption = "Log Out"
  79.             Forms!NavigationForm.tabJobEntry.Visible = True
  80.             Forms!NavigationForm.tabPlanning.Visible = False
  81.             Forms!NavigationForm.tabScheduling.Visible = False
  82.             Forms!NavigationForm.tabReporting.Visible = False
  83.             Forms!NavigationForm.tabJobEntry.Enabled = True
  84.             Forms!NavigationForm.tabPlanning.Enabled = False
  85.             Forms!NavigationForm.tabScheduling.Enabled = False
  86.             Forms!NavigationForm.tabReporting.Enabled = False
  87.             Forms!NavigationForm.tabSetting.Visible = False
  88.  
  89.     Case Else
  90.  
  91.         Me.txtUserName.Value = ""
  92.         Me.txtPassword.Value = ""
  93.  
  94.     End Select
  95.  
  96.     Forms!NavigationForm.Repaint
  97.  
  98.     DoCmd.BrowseTo _
  99.         objecttype:=acBrowseToForm, _
  100.         objectname:="frmJobOverview", _
  101.         PathtoSubformControl:="NavigationForm.NavigationSubform"
  102.  
  103.     'Call currentUserName(strUserName)                                           ' Store the log in name in function
  104.  
  105.     rstUser.Close
  106.     dbs.Close
  107.  
  108.     Set rstUser = Nothing
  109.     Set dbs = Nothing
  110.  
  111.     Exit Sub
  112.  
  113. errorHandler:
  114.  
  115.     MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
  116.  
  117. End Sub
  118.  
Oct 9 '14 #14
zmbd
5,501 Expert Mod 4TB
Sapo,
Not sure what is going on with your form.
I pulled your code into my generic test database and ran it thru... I even altered the target forms etc... always seemed to work as expected.

You may have something goofy with your form and recreating and pulling the form's objects back in will fix.

I've attached the test database... not 100% like yours, just the navigation form and some supporting forms and tables with generic stuff as this isn't supposed to be a working database (^_^)

-z


[edit] Take a look at your subform, frmJobOverview, if there is something wrong with this form (missing recordset, errors in bound controls, etc) it can cause issues with the loading into the navctrl.
Attached Files
File Type: zip BytesThread_958811-set-focus-problems-navigationform.zip (152.9 KB, 96 views)
Oct 9 '14 #15

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

Similar topics

2
by: Trev Hunter | last post by:
Hi Folks, Sorry if you have seen this post before - I've posted it before, but it seems to have gotten lost in Outlook limbo - it's visible on the web interface, but not in any news reader I've...
1
by: Jens Körte | last post by:
Hi NG! I encountered some strange behaviour when using focus() I use a form with several input-fields. A user can enter stuff. After entering I want to check the value, i.e. that a number is...
9
by: please-answer-here | last post by:
What is wrong with this code? when i place "return false" before the xfab assignment the form as intended doesn't submit. But when placed as here or in the last if/else construct the page gets...
3
by: Robert Oschler | last post by:
I have a textarea element that I have created an onblur() handler for. In the onblur() handler, I check to make sure that they have saved the contents of the edit box, before leaving it. If...
17
by: Neil Ginsberg | last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a form with a subform (in continuous form view). A combo box on the main form has code in the AfterUpdate event which adds a...
3
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having...
5
by: Michel Posseth [MCP] | last post by:
Hello we have encountered the following problems with the date time picker control A : datetime picker control gives focus to last entered field when moving back and forward with focus how do...
3
by: jan.loucka | last post by:
Hi, I looked around for this specific problem but could not find any answer - there's few things in VB but still nothing exactly like this so I'd appreciate any help. We're writing C# WinForm...
2
by: ramdil | last post by:
Hi All I have a form with section and multiple pages(tab sections) in the section.Now i have added a button in the form which when clicked will open a form.Now my problem is that when i click the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.