473,473 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VBA code fails to run when compiled?

3 New Member
I have another brief question. So I am trying to protect one form on my database from being accessed by people who don't need to edit the data. I found VBA code that essentially password protects the data (it compares an input string to a hardcoded string). The code (posted below) is put into the 'On Load Event' of the sensitive form.

It works fine when I am testing it in the database. However when I compile it to a .accde executable, it does not give the pop up window and challenge for a password. It simply allows access to the sensitive form.

I know that Access usually compiles the code and then deletes the source code, but is that what is causing the problem? Let me know if any of you have an ideas.

Thanks,
Tom

Code for thought:

Expand|Select|Wrap|Line Numbers
  1. Dim Password As String
  2.  Password = InputBox("Enter Administrator Password")
  3.  If Password = "mypasscode" Then
  4.  ' Open Form
  5.  DoCmd.OpenForm "AdminPage"
  6.  DoCmd.GoToRecord , , acNewRec
  7.  Else
  8.  MsgBox ("You're not authorized to access this page.")
  9.  DoCmd.Close
  10.  End If
  11.  
Jun 13 '13 #1
4 1216
ADezii
8,834 Recognized Expert Expert
Assuming your Code is in the Load() Event of the AdminPage Form, try:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Dim Password As String
  3.  
  4. Password = InputBox("Enter Administrator Password")
  5.  
  6. If Password = "mypasscode" Then
  7.   DoCmd.GoToRecord , , acNewRec
  8. Else
  9.   MsgBox ("You're not authorized to access this page.")
  10.     DoCmd.Close acForm, "AdminPage", acSaveNo
  11. End If
  12. End Sub
Jun 13 '13 #2
MMcCarthy
14,534 Recognized Expert Moderator MVP
Your problem is just with your logic. You are putting the code in the load event of the form you want to protect. Instead put it in the event that opens the form.

That way the form never opens if the password is incorrect.

Expand|Select|Wrap|Line Numbers
  1. Private Sub OpenMyForm()
  2. Dim Password As String
  3.  
  4.     Password = InputBox("Enter Administrator Password")
  5.  
  6.     If Password = "mypasscode" Then
  7.         ' Open Form
  8.         DoCmd.OpenForm "AdminPage", , , , acFormAdd
  9.     Else
  10.         MsgBox ("You're not authorized to access this page.")
  11.     End If
  12.  
  13. End Sub
You don't need a new command to go to new record as you can set that in the OpenForm. Also I removed the line to close the form. You don't need it as the form never opens if the password is not correct.
Jun 14 '13 #3
ADezii
8,834 Recognized Expert Expert
I took it from the perspective that AdminPage is the Start Up Form and subsequent entry into the DB. I may have missed the boat on this one! (LOL). Should my assumption be correct, a Quit as opposed to a Close would be in order anyway.
Jun 14 '13 #4
MMcCarthy
14,534 Recognized Expert Moderator MVP
You don't miss the boat very often so this one is allowed should it prove to be the case LOL!
Jun 14 '13 #5

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

Similar topics

0
by: Phil Powell | last post by:
When I view the page (chat.php) in IE 6.0 the following code is utilized: if ($_COOKIE) { // OPEN UP A NEW WINDOW TO SHOW THE CHATROOM ob_start();...
0
by: Ray S | last post by:
Does anyone know why a script that uses pipedream (which uses win32pipe.popen3()) will run a script, but hang when compiled? A script that uses pipedream.py won't run when compiled with McMillan...
1
by: ben | last post by:
When running the code below the validation fails when the first line of my xml contains <legalEnvelope version="1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema"...
1
by: CB | last post by:
Using C# in .Net 2003, DataSet.ReadXml fails when a percentage (%) sign is in the filename followed by 2 hex characters. Seems that the % sign is likely encoding the following 2 hex characters. ...
0
by: Segfahlt | last post by:
I have an inherited comboBox that I'm using to try to make an intellisense type box in VS 2003 .Net. It works okay when compiled in VS.Net 2002. It doesn't work when compiled in VS.Net 2003. In...
2
by: Robert Magnusson | last post by:
Hi all, I have a healthy class defined that happily serializes and deserializes from the underlying XML file. The problem I hit is that, as soon as I add an implicit conversion in any of the...
0
by: Arnaud Debaene | last post by:
Could someone explain why the following code works when compiled without /clr but fails at runtime with a boost::bad_function_call exception when compiled with /clr? #include <iostream> using...
9
by: BoloBaby | last post by:
I have an extremely vexing problem occurring in a program that I am writing. Consider the following block of code: Dim pDancer As New BEDancer mintIndex = mintIndex + 1 pDancer.DancerName =...
12
by: Jim Rodgers | last post by:
I have a big asp file that has an error under certain conditions -- totally repeatable. However, it only fails when I set response.buffer = True at the top. WHen I set it False in order to debug...
23
by: csolomon | last post by:
Hello: I have a form that allows me to add new records. In the onCurrent event, I have: Private Sub Form_Current() 'Requery Job Number Me.cbojobNumber.Requery 'Requery DM_Mix Combo...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.