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

ColumnOrder in Subform not performing as expected

35 32bit
Hello,

I have an option group on the main form that filters what records are displayed on the subform. The option group is named st.

I need to also reorder the columns on the subform if option 3 is chosen. I have to reorder several columns.

I have tried just one to see if it worked. The issue is that it reorders correctly if option 3 is chosen, but it does not reorder back to the original order if option 1 is chosen.

Here is the code. Can anyone tell me what the issue may be?

Expand|Select|Wrap|Line Numbers
  1. If st.Value = 3 Then
  2.     Forms!Default!NavigationSubform!Company.ColumnOrder = 1 
  3. And 
  4. Forms!Default!NavigationSubform![Account Number].ColumnOrder = 2
  5. Else If
  6.  st.Value = 1 Then
  7.     Forms!Default!NavigationSubform!Company.ColumnOrder = 2 And Forms!Default!NavigationSubform![Account Number].ColumnOrder = 1
  8. End If
  9. Forms!Default!NavigationSubform.Requery
  10. Me.Refresh
  11.  
Sep 1 '14 #1
9 1527
NeoPa
32,556 Expert Mod 16PB
Rhonda.

Why are you posting this code? It can't possibly even run like that. It doesn't even fit standard VBA syntax.

I tried to work out what your code might be like but it's so wrong that isn't even possible.

Please post your actual code - as tested and copied directly from your module. With that, we may have a starting point that can be worked with.
Sep 1 '14 #2
rhonda6373
35 32bit
I am posting the code because it does run. Thanks for the harsh answer, but forgive me I have not had VB in 10 years. Also, this is someone else's database with existing code in it. I would not be so condescending. I will figure this out on my own somehow.
Sep 1 '14 #3
NeoPa
32,556 Expert Mod 16PB
My intention is not to be condescending, so I apologise if I came across that way. My intention is to try to help. I cannot work with code that cannot run, as I need to be able to work out what it is you even expect to happen in order to suggest something likely to make that happen.

If I put a single word (And) on a line on its own in a VBA module then it will neither compile nor run (See your code line #3). I'm completely lost and I'm recognised as an Access MVP by Microsoft. The point I'm trying to emphasise here is that I do actually know quite a lot about VBA code and how to work with it.

If you say it runs then I'm sure you believe that. I have no suspicions on that score. I'm simply here to tell you that something doesn't add up. I'd stake my reputation on the statement that, as it's posted, that code cannot run in an Access VBA module.

I suspect you are not going to like what I'm saying, so I'm happy to back away from this thread if you would like me to. I'm not here to upset anyone. If, on the other hand, you'd like me to help try to sort out this very confusing problem, I'm happy to do what I can. The first thing I would suggest would be to look at it running using some of the debugging techniques - Debugging in VBA.
Sep 1 '14 #4
rhonda6373
35 32bit
No problem. I did not realize putting the and on a separate line would be such a problem -- I was just trying to make it easier to read. It is not coded on a separate line and the code does compile. I am not delusional (well maybe but not in this instance). As you can see, I am new to the site and don't fully understand how I am supposed to write these questions up.

Sorry for the confusion and the waste of any time. I do appreciate the help. I found another way to do this where it is easier to understand because there were over 15 columns that had to be hidden/re-ordered depending on what option was chosen.
Sep 1 '14 #5
NeoPa
32,556 Expert Mod 16PB
I have no suspicion that you're delusional Rhonda. What may seem relatively straightforward to you, however, often has hidden complications you may not be aware of though. Such that what appears to be the case may not be when you look under the hood. Without experience in any field it's easy to miss important points. No one should criticise you for that.

I know of members who've posted code they were sure was working only to discover later that it was never actually being run. This can happen easily with event handling procedures. I only determined the problem when I got hold of an actual copy of their project.

I would add that a number of members attempt to make life easier for those reading the question by reformatting the code in a more readable layout. While this can be frustrating, the fact that the intention is to try to make our life easier is generally recognised and appreciated. SQL is a prime case where this makes good sense. Unfortunately (For other reasons fortunately) VBA has many syntax rules that code must adhere to in order to be valid.

With your posted code, and assuming (We try to avoid assumptions as they can lead us a merry dance) lines #2 through #4 are actually on a single executable line, what we have is something very different from what I suspect you believe.

Instead of assigning 1 to Company.ColumnOrder and then assigning 2 to [Account Number].ColumnOrder what you actually have is :
  1. See if 1 and [Account Number].ColumnOrder have any bits in common (And is a bitwise operator that works on the two references each side of it).
  2. Check if the previous calculated value is equal to 2.
  3. Assign the previous (Boolean) result to Company.ColumnOrder

That being the case, you can see why I was convinced that something is very wrong with the code. I still suspect the actual code makes a lot more sense, but that's only a suspicion. I would need to see it directly to know for sure.

That said, it sounds as if you're happy with your alternative approach, and frankly, if you're happy then I am too. No need for more unless and until you decide you want to.
Sep 1 '14 #6
rhonda6373
35 32bit
Thanks, NeoPa. Understood. I will post the code as is in the future unless it is SQL.

Here is what I did in the event someone else is having issues with reordering columns in a subform based on a certain condition:

Expand|Select|Wrap|Line Numbers
  1. Select Case [st]
  2.    Case "3"
  3.       Forms!Default!NavigationSubform![Account Number].ColumnOrder = 1
  4.       Forms!Default!NavigationSubform!Company.ColumnOrder = 2
  5.       Forms!Default!NavigationSubform![CBS Lic #].ColumnOrder = 3
  6.       Forms!Default!NavigationSubform!Product.ColumnOrder = 4
  7.       Forms!Default!NavigationSubform![File Server].ColumnOrder = 5
  8.       Forms!Default!NavigationSubform![Term Server].ColumnOrder = 6
  9.       Forms!Default!NavigationSubform![Active Lic #].ColumnOrder = 7
  10.       Forms!Default!NavigationSubform![Pat Reg].ColumnOrder = 8
  11.       Forms!Default!NavigationSubform![Serv Conf].ColumnOrder = 9
  12.       Forms!Default!NavigationSubform![Impl Date].ColumnOrder = 10
  13.       Forms!Default!NavigationSubform![Software].ColumnOrder = 11
  14.       Forms!Default!NavigationSubform!WS.ColumnOrder = 12
  15.       Forms!Default!NavigationSubform![Hold Date].ColumnOrder = 13
  16.       Forms!Default!NavigationSubform![Time Zone].ColumnOrder = 14
  17.       Forms!Default!NavigationSubform![Notes].ColumnOrder = 15
  18.  
  19.       Forms!Default!NavigationSubform![Serv Conf].ColumnHidden = False
  20.       Forms!Default!NavigationSubform![Impl Date].ColumnHidden = False
  21.       Forms!Default!NavigationSubform![Software].ColumnHidden = False
  22.       Forms!Default!NavigationSubform!WS.ColumnHidden = False
  23.       Forms!Default!NavigationSubform![Hold Date].ColumnHidden = False
  24.  
  25.       Forms!Default!NavigationSubform![Frames Date].ColumnHidden = True
  26.       Forms!Default!NavigationSubform!Frames.ColumnHidden = True
  27.       Forms!Default!NavigationSubform![Cloud Ver].ColumnHidden = True
  28.       Forms!Default!NavigationSubform![Live Date].ColumnHidden = True
  29.       Forms!Default!NavigationSubform![Q Date].ColumnHidden = True
  30.       Forms!Default!NavigationSubform![Interfaces].ColumnHidden = True
  31.  
  32.       Case Else
  33.       Forms!Default!NavigationSubform![Account Number].ColumnOrder = 1
  34.       Forms!Default!NavigationSubform!Company.ColumnOrder = 2
  35.       Forms!Default!NavigationSubform![CBS Lic #].ColumnOrder = 3
  36.       Forms!Default!NavigationSubform!Product.ColumnOrder = 4
  37.       Forms!Default!NavigationSubform![File Server].ColumnOrder = 5
  38.       Forms!Default!NavigationSubform![Term Server].ColumnOrder = 6
  39.       Forms!Default!NavigationSubform![Pat Reg].ColumnOrder = 7
  40.       Forms!Default!NavigationSubform![Interfaces].ColumnOrder = 8
  41.       Forms!Default!NavigationSubform!Frames.ColumnOrder = 9
  42.       Forms!Default!NavigationSubform![Frames Date].ColumnOrder = 10
  43.       Forms!Default!NavigationSubform![Cloud Ver].ColumnOrder = 11
  44.       Forms!Default!NavigationSubform![Live Date].ColumnOrder = 12
  45.       Forms!Default!NavigationSubform![Active Lic #].ColumnOrder = 13
  46.       Forms!Default!NavigationSubform![Q Date].ColumnOrder = 14
  47.       Forms!Default!NavigationSubform![Time Zone].ColumnOrder = 15
  48.       Forms!Default!NavigationSubform![Notes].ColumnOrder = 16
  49.  
  50.       Forms!Default!NavigationSubform![Serv Conf].ColumnHidden = True
  51.       Forms!Default!NavigationSubform![Impl Date].ColumnHidden = True
  52.       Forms!Default!NavigationSubform![Software].ColumnHidden = True
  53.       Forms!Default!NavigationSubform!WS.ColumnHidden = True
  54.       Forms!Default!NavigationSubform![Hold Date].ColumnHidden = True
  55.  
  56.       Forms!Default!NavigationSubform![Frames Date].ColumnHidden = False
  57.       Forms!Default!NavigationSubform!Frames.ColumnHidden = False
  58.       Forms!Default!NavigationSubform![Cloud Ver].ColumnHidden = False
  59.       Forms!Default!NavigationSubform![Live Date].ColumnHidden = False
  60.       Forms!Default!NavigationSubform![Q Date].ColumnHidden = False
  61.       Forms!Default!NavigationSubform![Interfaces].ColumnHidden = False
  62.    End Select
  63.  
  64. DoCmd.SetWarnings False
  65.  
Sep 7 '14 #7
NeoPa
32,556 Expert Mod 16PB
Excellent. Have a look at this reworked version. I've assumed that the [st] ComboBox is actually numeric, in line with your original post, but if it isn't (String instead) then the change is very simple and only to line #2. I've also assumed that, as there are no changes to the column orders of many (The first six) of these controls, they are already in the correct position by design.
Expand|Select|Wrap|Line Numbers
  1. With Forms!Default.NavigationSubform.Form
  2.     Select Case [st]
  3.     Case 3
  4.         .[Active Lic #].ColumnOrder = 7
  5.         .[Pat Reg].ColumnOrder = 8
  6.         .[Serv Conf].ColumnOrder = 9
  7.         .[Impl Date].ColumnOrder = 10
  8.         .[Software].ColumnOrder = 11
  9.         .WS.ColumnOrder = 12
  10.         .[Hold Date].ColumnOrder = 13
  11.         .[Time Zone].ColumnOrder = 14
  12.         .[Notes].ColumnOrder = 15
  13.  
  14.         .[Serv Conf].ColumnHidden = False
  15.         .[Impl Date].ColumnHidden = False
  16.         .[Software].ColumnHidden = False
  17.         .WS.ColumnHidden = False
  18.         .[Hold Date].ColumnHidden = False
  19.  
  20.         .[Frames Date].ColumnHidden = True
  21.         .Frames.ColumnHidden = True
  22.         .[Cloud Ver].ColumnHidden = True
  23.         .[Live Date].ColumnHidden = True
  24.         .[Q Date].ColumnHidden = True
  25.         .[Interfaces].ColumnHidden = True
  26.     Case Else
  27.         .[Pat Reg].ColumnOrder = 7
  28.         .[Interfaces].ColumnOrder = 8
  29.         .Frames.ColumnOrder = 9
  30.         .[Frames Date].ColumnOrder = 10
  31.         .[Cloud Ver].ColumnOrder = 11
  32.         .[Live Date].ColumnOrder = 12
  33.         .[Active Lic #].ColumnOrder = 13
  34.         .[Q Date].ColumnOrder = 14
  35.         .[Time Zone].ColumnOrder = 15
  36.         .[Notes].ColumnOrder = 16
  37.  
  38.         .[Serv Conf].ColumnHidden = True
  39.         .[Impl Date].ColumnHidden = True
  40.         .[Software].ColumnHidden = True
  41.         .WS.ColumnHidden = True
  42.         .[Hold Date].ColumnHidden = True
  43.  
  44.         .[Frames Date].ColumnHidden = False
  45.         .Frames.ColumnHidden = False
  46.         .[Cloud Ver].ColumnHidden = False
  47.         .[Live Date].ColumnHidden = False
  48.         .[Q Date].ColumnHidden = False
  49.         .[Interfaces].ColumnHidden = False
  50.     End Select
  51. End With
NB. If this code is being run from within the module of the form named "Default" then any reference in the code to Forms!Default can be replaced with Me. If it's being run from the module of the form used within the subform then any reference to Forms!Default!NavigationSubform can be replaced with Me. Either is a good move generally as it makes the code easier to understand and easier to maintain.
Rhonda:
I will post the code as is in the future unless it is SQL.
Generally a good idea but not always absolutely necessary. I suspect as you gain more experience you will learn what can and cannot be changed without affecting the sense of it. It's always a good idea to warn if you are paracoding though (Like paraphrasing but with code - I just made that word up). That way if we end up at one of those "This just cannot possibly make sense." moments then we know to request the raw code from you ;-)
Sep 7 '14 #8
rhonda6373
35 32bit
Good tips, thanks! I will make those changes. Yes, st is numeric.
Sep 7 '14 #9
NeoPa
32,556 Expert Mod 16PB
You're welcome :-)

NB. I've made a very slight amendment to the code in order to make it more directly match the object being referenced. I updated the previous post with the changes.
Sep 7 '14 #10

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

Similar topics

1
by: Max Harvey | last post by:
Hi, I made up a nice little form which had its own sub form in it. I made a litle VB code so that when I pressed a button it would move form the form (frmConference) to the subform...
2
by: Cameron | last post by:
Hi, For the database I am currently working on, my employer would like the ability to use multiple combo boxes in order to filter the database. For instance the structure of the company is based...
2
by: CSDunn | last post by:
Hello, In an Access 2003 ADP Subform, I am trying to set the BackGround color of three textbox fields (LSScore, RScore, WScore) in the current record of the subform to zero (black) if the value of...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
0
by: P Mitchell | last post by:
Hello I would like someone to be able to help with the updating of data in a lookup list in a subform. In short, is their a VB instruction that is the equivalent of performing the action of...
1
by: xmp333 | last post by:
Hi, I have a form that is designed as a data sheet view. Attached to this is a subform with some VB code. When the user clicks on a row, the subform should pop up and run the VB code which...
2
by: Sagaert Johan | last post by:
Hi I have set the columreorder to true Is there a way to get/set the current columnorder, so i can restore the order from a saved setting ? Johan
9
by: robert d via AccessMonster.com | last post by:
I'm not sure why the following isn't working. The subform loads correctly, but no data is displayed. I'm certain that there is data and I have checked that the SQL statement does in fact return...
9
by: chickenhawk | last post by:
I'm using a search engine in VBA to return a new RecordSource to a SubForm, but when I attempt to apply the new SQL code as the RecordSource to the SubForm which contains the data the user wants to...
15
AdamHope
by: AdamHope | last post by:
I want to create a Save Layout button, so that clicking this button saves the ColumnOrder, ColumnWidth and ColumnHidden ect. for each column in the subform datasheet to a seperate layouts table with...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.