473,385 Members | 1,606 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.

Brand New to Access need Assist with Search via txt box in a form

I have the database imported from an excel spreadsheet.

I am using the Asset Template for Access (Office365 ProPlus version 1904).

The filter form and table were not needed so I removed them.

My need:
I am looking for a simple search function that allows me to Search across 4 - 5 columns for specific or keyword information in the form. I would prefer to not use a query if at all possible.

What I have done thus far:
I took the filters macro that came with the template and converted it to VBA for easier editing. (My VBA knowledge is very basic FYI) I added and removed things I knew I didn't need like setting up temp vars in reference to the Filter Details Form and Table. Under QuickSearch, I changed the filter names for the columns to the columns I had imported from the Excel Spreadsheet.

My Issue:
I am currently having an issue trying to get the Command Buttons to either call the function from the Module via Macro or to use an Event Procedure to call the specific Function from the Module.

I would graciously accept any assistance you guys can provide.

Thanks in Advance!

Code is below:
Expand|Select|Wrap|Line Numbers
  1. Attribute VB_Name = "Converted Macro- Filters"
  2. Option Compare Database
  3.  
  4. '------------------------------------------------------------
  5. ' Filters
  6. '
  7. '------------------------------------------------------------
  8. Function Filters()
  9. On Error GoTo Filters_Err
  10.  
  11.     Beep
  12.     ' Macro can't be run from the navigation pane.
  13.     Exit Function
  14.  
  15.  
  16. Filters_Exit:
  17.     Exit Function
  18.  
  19. Filters_Err:
  20.     MsgBox Error$
  21.     Resume Filters_Exit
  22.  
  23. End Function
  24.  
  25. '------------------------------------------------------------
  26. ' Filters_ClearFilter
  27. '
  28. '------------------------------------------------------------
  29. Function Filters_ClearFilter()
  30. On Error Goto Filters_ClearFilter_Err
  31.  
  32.     With CodeContextObject
  33.         If (CurrentProject.IsTrusted And .Form.Name = "Asset List") Then
  34.             .Form!cboFilterFavorites = ""
  35.         End If
  36.         ' Clear Filter
  37.         DoCmd.ApplyFilter "", """""", ""
  38.         If (.Form.Name = "Asset List" And Not (.Form!chkShowRetired)) Then
  39.             ' Filter out Retired assets if checkbox is cleared
  40.             DoCmd.ApplyFilter "", Eval("""[Retired Date ] is null or [Retired Date ] > date()"""), ""
  41.         End If
  42.         DoCmd.GoToControl "txtSearchBox"
  43.         DoCmd.SetProperty "cmdSearchClear", acPropertyVisible, "0"
  44.         DoCmd.SetProperty "iconSearchClear", acPropertyVisible, "0"
  45.         DoCmd.SetProperty "cmdSearchGo", acPropertyVisible, "-1"
  46.         If (CurrentProject.IsTrusted) Then
  47.             .txtSearchBox = ""
  48.         End If
  49.         Exit Function
  50.     End With
  51.  
  52.  
  53. Filters_ClearFilter_Exit:
  54.     Exit Function
  55.  
  56. Filters_ClearFilter_Err:
  57.     MsgBox Error$
  58.     Resume Filters_ClearFilter_Exit
  59.  
  60. End Function
  61.  
  62. '------------------------------------------------------------
  63. ' Filters_QuickSearch
  64. '
  65. '------------------------------------------------------------
  66. Function Filters_QuickSearch()
  67. On Error Goto Filters_QuickSearch_Err
  68.  
  69.     With CodeContextObject
  70.         If (.txtSearchBox = "") Then
  71.             ' Clear Filter when search box empty
  72.             DoCmd.RunMacro "Filters.ClearFilter", , ""
  73.             End
  74.         End If
  75.         If (VarType(.txtSearchBox) <> 8) Then
  76.             End
  77.         End If
  78.         DoCmd.SetProperty "cmdSearchGo", acPropertyVisible, "-1"
  79.         If (.txtSearchBox = "" And .cmdSearchClear.Visible <> 0) Then
  80.             DoCmd.SetProperty "cmdSearchClear", acPropertyVisible, "0"
  81.             End
  82.             DoCmd.SetProperty "iconSearchClear", acPropertyVisible, "0"
  83.         End If
  84.         ' Handle "'s in search
  85.         TempVars.Add "strSearch", Replace(.txtSearchBox, """", """""")
  86.         ' Build the Filter for the Asset list
  87.         If (.Form.Name = "Asset List") Then
  88.             TempVars.Add "strFilter", "([Status] Like "" * " & [TempVars]![strSearch] & " * "" )"
  89.         End If
  90.         If (.Form.Name = "Asset List") Then
  91.             TempVars.Add "strFilter", TempVars!strFilter & " OR ([Account/Matter] Like "" * " & [TempVars]![strSearch] & " * "" )"
  92.         End If
  93.         If (.Form.Name = "Asset List") Then
  94.             TempVars.Add "strFilter", TempVars!strFilter & " OR ([Container] Like "" * " & [TempVars]![strSearch] & " * "" )"
  95.         End If
  96.         If (.Form.Name = "Asset List") Then
  97.             TempVars.Add "strFilter", TempVars!strFilter & " OR ([NTID] Like "" * " & [TempVars]![strSearch] & " * "" )"
  98.         End If
  99.         If (.Form.Name = "Asset List") Then
  100.             TempVars.Add "strFilter", TempVars!strFilter & " OR ([BP Barcode] Like "" * " & [TempVars]![strSearch] & " * "" )"
  101.         End If
  102.  
  103.         ' Apply the Filter
  104.         DoCmd.ApplyFilter "", TempVars!strFilter, ""
  105.         TempVars.Remove "strFilter"
  106.         TempVars.Remove "strSearch"
  107.         DoCmd.SetProperty "cmdSearchClear", acPropertyVisible, "-1"
  108.         DoCmd.SetProperty "iconSearchClear", acPropertyVisible, "-1"
  109.         DoCmd.GoToControl "txtSearchBox"
  110.         DoCmd.SetProperty "cmdSearchGo", acPropertyVisible, "-1"
  111.     End With
  112.  
  113.  
  114. Filters_QuickSearch_Exit:
  115.     Exit Function
  116.  
  117. Filters_QuickSearch_Err:
  118.     MsgBox Error$
  119.     Resume Filters_QuickSearch_Exit
  120.  
  121. End Function
  122.  
  123.  
May 29 '19 #1
1 1318
twinnyfo
3,653 Expert Mod 2GB
soapbox3000,

Welcome to Bytes!

First, before we get too far down the "this is really an overcomplexification of avery simple thing" road, I want to ask exactly what it is you are trying to do? It looks like one of the most complicated basic searches I've every seen.

If, you simply want to "search for" something, then, if the form has the navigation buttons displayed (which is a built in feature of Access forms), then just use the search box at the bottom of your form.

But, If you must actually create a filter for the records you are displaying, that is an entirely different story and there is probably a series of additional questions, answers and calrifying details we will need on this one.

Don't give up hope--we just need to know more before we can give you better guidance.
May 30 '19 #2

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

Similar topics

6
by: Jules | last post by:
Hi: I have an Access 97 Search form set up - a couple of combo boxes, a couple of text fields and a command button. I want the command button to run an SQL script and then open the results form....
1
by: Guest | last post by:
I have 2 tables: 1/ English 2/ Deutsch Which is the best way to make form who is going to scan words from table English to get meaning ( translation) from table Deutsch. Of course I need...
1
by: Chris | last post by:
I need a search form to perform. I have a Form and a subform. The subform is based off a query and the main form is unbound. The query runs perfect, however, I have a command button in the main...
1
by: tamoochin | last post by:
I have a form that registers the user with my website, the form is in farsi language and must use utf-8 standard. I can store data in MS Access and also read it back with any problems. the...
2
by: Mark | last post by:
Hi All, I am creating a music database for a friend and have run into a problem. Within the ALBUM table, I wanted to store the ARTIST_ID rather than the ARTIST_NAME. To do this, I intended to have...
4
by: Twisted01 | last post by:
Hello, I am new here and I hope I have the correct forum to answer my question. I am creating a website for a friend and they need a "Search Form" so that visitors can search for items on the...
2
by: zandiT | last post by:
Hello everyone i have a mainform called frmMain and it has 2 subforms. the frmMain consists of 2 combo boxes. i want to create a search form whereby the user can choose an option in combo1 and in...
11
by: woodey2002 | last post by:
This problem is driving me crazy. Hello there, i am trying to create a search form for records in my access database. The search form will contain text boxes and a multi select list box. The user...
9
f430
by: f430 | last post by:
i have been trying to write a search code for a similar database, and i followed all the steps that were provided above, and my code was close to what lightning had but i have added date range in my...
3
by: Breanna | last post by:
I am very very new to access trying to get a database set up for a new company I work for. So I apologize for the long post. I am not sure what all information is needed to help me and I don't want...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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...

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.