By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,140 Members | 1,301 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,140 IT Pros & Developers. It's quick & easy.

Access Form Load-Active-Current Code Execution Issue

P: 1
I have an access database that I am developing for use each day. I am a relatively inexperienced vba user, so I am using/reusing a lot of code that I have developed for specific tasks, learning new material, and integrating code I am finding that fits specific needs from the internet from various sights (yes I understand the risks associated with this)

The issue I am having is related to code executing when my main form is being loaded. I have a large number of things that happen: text box back colors standardize to grey, command button captions change, network drives are mapped, file objects are checked for last modified date and written into a table....

When I put the code on a command button, it all works perfectly. When I put it in the form Load or form Current, it throws runtime 2475 indicating that the form has to be active for the "strFormName = Screen.ActiveForm.Name" to be used. While it seems obvious, I can't seem to figure out which event that I can put this in that will still work...otherwise I need to change the code so that it will somehow work.

code snippet ---
Expand|Select|Wrap|Line Numbers
  1. Georeport = Array("BRAZIL", "CANADA", "MEXICO", "SSA", "UNITED_STATES")
  2. intcounter = 0
  3. While intcounter < 5
  4.     reportname = Georeport(intcounter)
  5.     rst.FindFirst ("[Support File Name] LIKE 'Identity_Management_Comp_imt_overview_" & reportname & ".csv'")
  6.     LastMod = rst![Support File Modified Date]
  7.     MonName = rst![MonitorName]
  8.     ButName = rst![CommandButtonName]
  9.     If LastMod < Date Then
  10.         strFormName = Screen.ActiveForm.Name
  11.         Forms!frm_Main.Controls(MonName).BackColor = 4678655
  12.         Forms!frm_Main.Controls(ButName).Caption = "Recheck"
  13.  
  14.     Else
  15.         strFormName = Screen.ActiveForm.Name
  16.         Forms!frm_Main.Controls(MonName).BackColor = 65280
  17.         Forms!frm_Main.Controls(ButName).Caption = "Replace"
  18.  
  19.     End If
  20.     intcounter = intcounter + 1
  21. Wend
Jun 19 '12 #1

✓ answered by dsatino

Well, I think the most obvious thing to do if the form name isn't dynamic is to simply write in the form name instead of using the active form reference.

Share this Question
Share on Google+
1 Reply


dsatino
100+
P: 393
Well, I think the most obvious thing to do if the form name isn't dynamic is to simply write in the form name instead of using the active form reference.
Jun 19 '12 #2

Post your reply

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