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

My function is not running.

2
I need to filter a filtered data.
attach is my code (I copy from one of the online project and suiting to my need, so u can see a lot of comment because im doing editing through trial and error)

The proper date "if" im not using it but I am afraid i might leak out some clue if i deleted it.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFilter_Click()
  2. Dim ws As Worksheet
  3. 'set worksheet variable
  4. Set ws = Sheet1
  5. 'Make sure it is a proper date
  6. 'If Not IsDate(Me.txtDateStart) And Me.txtDateStart <> "" Then
  7. 'MsgBox "This is not a proper date"
  8. 'Me.txtDateStart = ""
  9. 'Exit Sub
  10. 'End If
  11. 'Make sure it is a proper date
  12. 'If Not IsDate(Me.txtDateFinish) And Me.txtDateFinish <> "" Then
  13. 'MsgBox "This is not a proper date"
  14. 'Me.txtDateFinish = ""
  15. 'Exit Sub
  16. 'End If
  17. 'send the values to the worksheet
  18. With ws
  19. '.Range("C6").Value = Format(Me.txtDateStart.Value, "dd/mm/yyyy")
  20. '.Range("D6").Value = Format(Me.txtDateFinish.Value, "dd/mm/yyyy")
  21. .Range("AO2").Value = Me.Sc1.Value
  22. .Range("AP2").Value = Me.Sc2.Value
  23. .Range("AQ2").Value = Me.Sc3.Value
  24. .Range("AR2").Value = Me.Sc4.Value
  25. .Range("AS2").Value = Me.Sc5.Value
  26. .Range("AT2").Value = Me.Sc6.Value
  27. .Range("AU2").Value = Me.Sc7.Value
  28. .Range("AV2").Value = Me.Sc8.Value
  29. .Range("AW2").Value = Me.Sc9.Value
  30. .Range("AX2").Value = Me.Sc10.Value
  31. .Range("AY2").Value = Me.Sc11.Value
  32.  
  33. End With
  34. 'run the advanced filter
  35. 'If ws.Range("N9").Value <> "" Then
  36.  
  37. 'Me.lstTool.RowSource = ""
  38.  
  39. Filterme
  40.  
  41. 'Clearme
  42. 'End If
  43. 'add the named range to the rowsource
  44. 'If ws.Range("AC9").Value = "" Then
  45. 'Me.lstTool.RowSource = "outdata"
  46. 'MsgBox "No matching data"
  47. 'Else
  48.  
  49. Me.lstTool.RowSource = "FilterData"
  50.  
  51. 'End If
  52. End Sub
My Filterme just don't run. I have been doing trial and error by commenting some of the sentence, and the "Filterme" do run sometime (I suppose so because i got my filtered data) and I have no clue why.
Nov 1 '15 #1
3 1263
zmbd
5,501 Expert Mod 4TB
Line 39 of the code block (thnx Rabbit) and the subsequent line 41 most likely refer to another VBA code module. Without that information there is very little we can do to help you with this code. Additionally, the code is so heavily commented it's hard to tell just what you were/are attempting.

I may be worth while for you to take a moment and explain what it is that you are attempting to do and how you are attempting to accomplish this goal.
Nov 1 '15 #2
OL93
2
Thanks for your rapid reply!

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFilter_Click()
  2.    Dim ws As Worksheet
  3.    'set worksheet variable
  4.    Set ws = Sheet1
  5.    'send the values to the worksheet
  6.    With ws
  7.       .Range("AO2").Value = Me.Sc1.Value
  8.       .Range("AP2").Value = Me.Sc2.Value
  9.       .Range("AQ2").Value = Me.Sc3.Value
  10.       .Range("AR2").Value = Me.Sc4.Value
  11.       .Range("AS2").Value = Me.Sc5.Value
  12.       .Range("AT2").Value = Me.Sc6.Value
  13.       .Range("AU2").Value = Me.Sc7.Value
  14.       .Range("AV2").Value = Me.Sc8.Value
  15.       .Range("AW2").Value = Me.Sc9.Value
  16.       .Range("AX2").Value = Me.Sc10.Value
  17.       .Range("AY2").Value = Me.Sc11.Value
  18.    End With
  19.    'run the advanced filter
  20.    Filterme
  21.    Me.lstTool.RowSource = "FilterData"
  22. End Sub
This is my sub in my module

Expand|Select|Wrap|Line Numbers
  1. Sub Filterme()
  2.    '
  3.    ' Filterme Macro
  4.    '
  5.    Selectme
  6.    '
  7.    Sheet1.Range("N8").CurrentRegion.AdvancedFilter _
  8.       Action:=xlFilterCopy, _
  9.       CriteriaRange:=Range( _
  10.          "AO1:AY2"), _
  11.       CopyToRange:=Sheet1.Range("AC8:AM10000"), _
  12.       Unique:=False
  13. End Sub
I am filtering the result of another filtered table.
I am using line 39 to call my Filterme sub. But It just doesn't work . I made a button on my sheet table and assigned macro (Filterme) to it and it works well (when I manually click it), but when I trying to call Filterme in my userform it just doesn't work.
Thanks in advance!
Nov 2 '15 #3
zmbd
5,501 Expert Mod 4TB
First I'd follow the VBA troubleshooting steps as outlined here: > Before Posting (VBA or SQL) Code
Keep in mind, that although we're referring to MS-Access in this link, the basic VBA trouble shooting in Section A will still apply. Also, please read section B.

Once you have the Option Explicit set and the debug/compile cleared (you may have to run this several times - the compiler will stop on each error it finds.) Then, insert the STOP command in your code... between lines 5 and 6 might be a good place.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFilter_Click()
  2.     Dim ws As Worksheet
  3.     'set worksheet variable
  4.     Set ws = Sheet1
  5.     'send the values to the worksheet
  6. STOP
  7.     With ws
  8.  
Now run your code... it should open the VBA editor in debug mode at the STOP command. Use [F8] to step thru your code and make sure that each line is being executed.
Nov 2 '15 #4

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

Similar topics

5
by: Martoni | last post by:
Can anyone see what's wrong with this function? Running the query directly in MySQL produces correct results (ie a value for free and total_entitlement). function Count_licenses($sID) { global...
9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
9
by: drhowarddrfinedrhoward | last post by:
I see a number of pages with functions like MM_somefunction(). Where does the MM_ come from? I don't see it in any books I'm studying.
1
by: Sipho | last post by:
Hi, I need to instantiate a VB6 function and call it from javascript in ASP. <script language='javascript'> function onScheduleTask() { var ocuScheduler ocuScheduler = new...
12
by: windandwaves | last post by:
Hi Gurus When I have a query in which I use a small function, e.g.: SELECT A03_FILES.ID, A03_FILES.D, hasvt() AS hsvVT FROM A03_FILES; where HasVT is defined below: --------------------
2
by: Yeounkun, Oh | last post by:
Hello, I want to know the name of function() in program. In "gcc", I know that __FUNCTION__ macro is used for getting that. but in "cc", __FUNCTION__ macro does not exist. I can't find function...
1
by: ApexData | last post by:
Hello I have an UNBOUND textbox Text1 that I want to validate in code. I want to lock the user into the field until Valid Data is entered. I created the following Function: Private Function...
4
by: Larry | last post by:
On the following page: http://www-128.ibm.com/developerworks/db2/library/techarticle/dm-0407zhang/index.html IBM discusses a surrogate key generation function, along with a listing in Java...
2
360monkey
by: 360monkey | last post by:
I recently tried to start learning GUI for python, and reverted back to python 2.6.4 my question: in python 3.1.1,: >>>import title >>>title.class.function() >>>running program in python...
3
Yozuru
by: Yozuru | last post by:
Hello good people of Byte, I am running into a TypeError: unsupported operand type(s) for -: 'str' and 'int' For example when I run: realdate() The error occurs. This is what I have for my...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.