473,324 Members | 2,196 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,324 software developers and data experts.

code works in one form but not another

I have the following code in one access 2013 form attached to a button to be preformed 'on click'

Expand|Select|Wrap|Line Numbers
  1. Private Sub Find_by_Facility_Click()
  2. Dim Searchstrg As String
  3. Searchstrg = InputBox("Facility to Search")
  4. Me.Filter = "[Facility Name] Like '*" & Searchstrg & "*'"
  5. Me.FilterOn = True
  6. Remove_Filter.Visible = True
  7. End Sub 
It works perfectly!! However, I then copied the code into a second form (and yes, I did change all references/connections)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Find_by_Facility_Click()
  2. Dim Searchxyz As String
  3. Searchxyz = InputBox("Facility to Search")
  4. Me.Filter = "[Facility Name1] Like '*" & Searchxyz & "*'"
  5. Me.FilterOn = True
  6. Remove_Filter1.Visibile = True
  7. End Sub 
(please forgive my horrible naming conventions)
But the code in the second form gives me an error - "object or event does not support the set of events".

Can anyone help me figure out what's going on here?
Mar 3 '16 #1

✓ answered by jforbes

There's really only one thing that I can think of to try. You can try un-compiling and recompiling your database.

The easiest way that I've found to do this:
  • first make a backup copy of your database
  • then from the Run Prompt (Windows Key+R), run "msaccess /decompile"
  • ...Access will start up and the first database that you open will be de-compiled
  • Open your database
  • (Alt+F11) to open the VBA Editor
  • Debug|Compile

7 1966
jforbes
1,107 Expert 1GB
I think there is a typo on line 6 of your second code block, this might or might not be your problem:
Expand|Select|Wrap|Line Numbers
  1. Remove_Filter1.Visibile = True
If that is not it, when you compile your database, do you get an error?
Mar 3 '16 #2
Thanks for pointing out the typo, but no it didn't change anything. When compiled I don't get any errors. It seems to not even start, I can tell because if I go back to the working code and mess it up then run it, it at least prompts me with the inputbox and then fails.
Mar 3 '16 #3
jforbes
1,107 Expert 1GB
I'm a little confused about whether or not you are getting error. Your first post lists one and I assume it's a runtime error, but your second post gives the impression that you aren't getting an error and that nothing is happening.

Sometimes when copying and pasting Controls and Code from one Form to another, the association between the Control and Code can get lost. When this happens, you can click on a command button till the cows come home, but nothing happens. To re-associate a Control and it's code, you can right click on a Control and select Build Event... and then select code and if the code block is named correctly, it will get re-associated with the Control.
Mar 3 '16 #4
I've made sure all the associations are there, I've even tried deleting the button, starting from scratch, and typing the code in but I end up in the same place (sometimes I get incorrect use of "Me" errors but I haven't today for some reason so who knows). I've also tried switching out 'Me.' with the longer 'Forms.frm[My Form's Name]' but again it'll work in the first form but not the second. Also each form is linked to it's own table so there's no conflict
like trying to filter one table via two different forms.

When I go to compile no errors pop up, nothing's wrong. After I switch to Form view and click the actual button an error pops up saying "The expression On Click you entered as the event property setting produced the following error: Object or class does not support the set of events." I've never gotten this error in the first form, only the second form. I've also tried renaming the subs to something completely different (thinking I can't use the same name if it's already used in another form) but that doesn't do anything
Mar 3 '16 #5
Alright I just exported the second form and it's underlying table to a new access database and it works! I then re-exported it back to the original database and everything works. I guess it was just a bug in Access?
Mar 3 '16 #6
jforbes
1,107 Expert 1GB
There's really only one thing that I can think of to try. You can try un-compiling and recompiling your database.

The easiest way that I've found to do this:
  • first make a backup copy of your database
  • then from the Run Prompt (Windows Key+R), run "msaccess /decompile"
  • ...Access will start up and the first database that you open will be de-compiled
  • Open your database
  • (Alt+F11) to open the VBA Editor
  • Debug|Compile
Mar 3 '16 #7
Thanks! Your solution worked too, (I tried it on a previous copy which wasn't working). So I guess when I exported the table and form to a blank database it reset everything which is why it worked.
Mar 3 '16 #8

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

Similar topics

0
by: ht | last post by:
hi all, im kinda new to vb and i have code that unhides a hidden from on a key press for some reason though this code only works when running th app through by, ie. it wont work in the...
1
by: Razarr69 | last post by:
I have a ASP application that I am using for my company and it is currently running on a Windows 2000 server box with IIS 5. The code works perfectly there (except for handling large files - due...
4
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
1
by: Avi | last post by:
Hi All. This code works very fine in Firefox but not in I.E. Can anybody help me out? it gives ... "Unknown Runtime Error" in I.E. This code ... Stores N*2 Matrix at Client Side & provide the...
6
by: traversd | last post by:
Hi there, this is driving me nuts! i have a program that is to be run over night, no interaction from the user. I want the code to start runing when the program is started, but i also want to...
9
by: ad | last post by:
I use the codes below to clear the cookie: HttpCookie myCookie = new HttpCookie("us_id"); myCookie.Expires = DateTime.Now.AddDays(-1d); Response.Cookies.Add(myCookie); It do well when the...
6
by: Crash | last post by:
C# VS 2003 ..Net Framework V1.1 SP1 SQL Server 2000 SP3 Enterprise Library June 2005 I'm working with some code {not of my creation} that performs the following sequence of actions: - Open...
1
by: reemamg | last post by:
Have a piece of code which works in Firefox however doesnt work in IE <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <meta...
3
by: PrabodhanP | last post by:
I hv following javascript form validation code works in IE but not in Mozilla-Firefox ...please suggest <script type="text/javascript"> function IsNumeric(strString) // check for valid...
0
by: kprawin | last post by:
Hi sir, Im new to Visual Basic, and I tried a simple application using VB2008 and MS-Access. It is a simple application to store Employee ID, Employee Name and Employee Photo. Both Employee ID and...
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: 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...
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
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: 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.