Problem with code to open a form based on value in checkbox (1 Viewer)

JackieEVSC

Registered User.
Local time
Yesterday, 19:10
Joined
Feb 24, 2012
Messages
26
I have a database that, when I send out a new frontend, the users have to enter their defaults (their name and location etc). They often forget to set these, even though I tell them to set them in the email announcing the new frontend.

So ... I created a form (frm_SetDefaults) that has a checkbox for so that they aren't prompted to set their defaults every time they open the database. frm_SetDefaults is based on a table called tbl_DefaultsSet with only one field (DontShowAgain).

When the database opens, I want it to open frm_SetDefaults UNLESS the "don't show again" checkbox is checked. In that case, I want it to open frm_Main instead.

I have tried so many variations of code that my brain is bleeding! I'm sure this is a simple thing to do for someone who knows vba, but my skill level of vba is rudimentary at best. I would be very grateful if someone could help me with this code.

Thanks,
Jackie
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:10
Joined
Aug 30, 2003
Messages
36,126
I'd probably have an autoexec macro that called a function. That function would lookup the value from the table and open the appropriate form. You could also put code in the load event of the default form that checked and if appropriate closed itself and opened the other. It would help to see your code to figure out what's wrong with it. ;)
 

sneuberg

AWF VIP
Local time
Yesterday, 17:10
Joined
Oct 17, 2014
Messages
3,506
You could put a function something like the following in a module, save the module, and call it from an Autoexec macro.

Code:
Public Function Start()

If DLookup("[DontShowAgain]", "[tbl_DefaultsSet]") = False Then
    DoCmd.OpenForm "frm_SetDefaults", acNormal
Else
    'Open the other form
End If

End Function

Note than when you add a run code line in a macro the Intellisense will put the function in for you but leave off the closing parenthesis, e.g. "Start(" You need to add it so its like "Start()"

Why don't you save these defaults in a backend table so they don't have to do this?
 

JackieEVSC

Registered User.
Local time
Yesterday, 19:10
Joined
Feb 24, 2012
Messages
26
Users don't login to the database, so there's no way (that I know of!) to capture their default name, and the location(s) they select can change according to what data they are trying to capture in their reports.

I'll give your code a try ... and thanks for your help.
 

sneuberg

AWF VIP
Local time
Yesterday, 17:10
Joined
Oct 17, 2014
Messages
3,506
Users don't login to the database, so there's no way (that I know of!) to capture their default name, and the location(s) they select can change according to what data they are trying to capture in their reports.

Maybe Environ("ComputerName") would be good enough to identify them. I think they are unique to the frontend in a network environment. It's not likely that they would change from one version of a frontend to the next.
 

JackieEVSC

Registered User.
Local time
Yesterday, 19:10
Joined
Feb 24, 2012
Messages
26
sneuberg,

I wasn't able to create a startup macro, but I put the code in onload and set that form as the default form when opening the database (I had to add a docmd.close to the frm_SetDefaults so that it didn't remain open), and it works! It may not be not sexy, but I get the desired results! Thank you SO much for your help!!
 

sneuberg

AWF VIP
Local time
Yesterday, 17:10
Joined
Oct 17, 2014
Messages
3,506
That's just as good. I suggested the Autoexec route as I thought that was easier to understand. Glad you got it working.
 

Frothingslosh

Premier Pale Stale Ale
Local time
Yesterday, 20:10
Joined
Oct 17, 2012
Messages
3,276
The startup macro *MUST* be named AutoExec. And the macro action to run a function is RunCode. Also, it can only run functions, not subs. So what you do is create AutoExec, as its one option have it RunCode, then name the function you want it to run - I just use Startup(). Then just have a function of that name saved in a regular old code module (can't have the same name as any functions), and you're good to go.

You really should make sure you eventually learn to set that up, because that'll give you a lot more flexibility in future projects. :) You can check login credentials, check for updates, run needed maintenance, open specific forms, pretty much anything you want.
 

Users who are viewing this thread

Top Bottom