473,804 Members | 3,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Modify Code

In Access 97, I have a form named frmEmpList with a list box that
contains the names of all our employees. I have a command button with
the following code in the OnClick event so the form will open showing
only the record of the employee selected from the list:

Dim varSelected As Variant
Dim strSQL As String
If IsNull(Me![EmpList]) Then
MsgBox "You must select an employee's name from the list.",
vbExclamation, "NOTE"
Else
For Each varSelected In Me!EmpList.Item sSelected
strSQL = strSQL & Me!EmpList.Item Data(varSelecte d) & ","
Next varSelected
If strSQL <> "" Then
strSQL = "[Employees].[EmployeeNumber] IN (" & Left(strSQL,
Len(strSQL) - 1) & ")"
DoCmd.OpenForm "frmVacationWee ks", acViewNormal, , strSQL
End If
End If

What I'm trying to do is password protect frmVacationWeek s. I made a
Password form to prompt for a password with an unbound text box and
the following code in the OnClick event of a command button:

If Me!txtPassword = "password" Then
DoCmd.OpenForm "frmVacationWee ks"
DoCmd.Close acForm, "frmPasswor d"
Else
MsgBox "Incorrect Password", vbOKCancel
End If

Here's what happens - I have frmEmpList open, I select an employee
from the list, click the command button, and frmPassword opens. I
type in the correct password, frmPassword closes, and frmVacationWeek s
opens, but instead of showing the employee I selected from the list,
the first employee in the list shows. So, in effect, frmPassword
"interrupts " the code in the OnClick event of frmEmpList. How can I
modify the code so I can accomplish what I want to do?

By the way, I don't know a lot about VBA - someone helped me with the
code above. Thanks in advance for your help.
JD
Nov 12 '05 #1
2 3385
I think this has to do with the fact that it is not this line that
finally opens frmVacationWeek s

DoCmd.OpenForm "frmVacationWee ks", acViewNormal, , strSQL

but this one instead:

DoCmd.OpenForm "frmVacationWee ks"

and it does not pass any parameters to the form as it is being opened.
Try putting your password code in the main code module, but make sure
that "password" text box is also the part of the main form:

Dim varSelected As Variant
Dim strSQL As String
Dim bGotPwd as Boolean
bGotPwd = (Me!txtPassword = "password")
If IsNull(Me![EmpList]) Then
MsgBox "You must select an employee's name from the list.",
vbExclamation, "NOTE"
Else
For Each varSelected In Me!EmpList.Item sSelected
strSQL = strSQL & Me!EmpList.Item Data(varSelecte d) & ","
Next varSelected
If strSQL <> "" Then
strSQL = "[Employees].[EmployeeNumber] IN (" & Left(strSQL,
Len(strSQL) - 1) & ")"
if bGotPwd then _
DoCmd.OpenForm "frmVacationWee ks", acViewNormal, , strSQL else _
MsgBox "Sorry, bad password"
End If
End If

Good luck,
Pavel
"jd****@yahoo.c om" wrote:

In Access 97, I have a form named frmEmpList with a list box that
contains the names of all our employees. I have a command button with
the following code in the OnClick event so the form will open showing
only the record of the employee selected from the list:

Dim varSelected As Variant
Dim strSQL As String
If IsNull(Me![EmpList]) Then
MsgBox "You must select an employee's name from the list.",
vbExclamation, "NOTE"
Else
For Each varSelected In Me!EmpList.Item sSelected
strSQL = strSQL & Me!EmpList.Item Data(varSelecte d) & ","
Next varSelected
If strSQL <> "" Then
strSQL = "[Employees].[EmployeeNumber] IN (" & Left(strSQL,
Len(strSQL) - 1) & ")"
DoCmd.OpenForm "frmVacationWee ks", acViewNormal, , strSQL
End If
End If

What I'm trying to do is password protect frmVacationWeek s. I made a
Password form to prompt for a password with an unbound text box and
the following code in the OnClick event of a command button:

If Me!txtPassword = "password" Then
DoCmd.OpenForm "frmVacationWee ks"
DoCmd.Close acForm, "frmPasswor d"
Else
MsgBox "Incorrect Password", vbOKCancel
End If

Here's what happens - I have frmEmpList open, I select an employee
from the list, click the command button, and frmPassword opens. I
type in the correct password, frmPassword closes, and frmVacationWeek s
opens, but instead of showing the employee I selected from the list,
the first employee in the list shows. So, in effect, frmPassword
"interrupts " the code in the OnClick event of frmEmpList. How can I
modify the code so I can accomplish what I want to do?

By the way, I don't know a lot about VBA - someone helped me with the
code above. Thanks in advance for your help.
JD

Nov 12 '05 #2
Pavel, thanks for your reply. I did as you suggested, but in testing
this to see what the users would see if they click the command button
to open frmVacationWeek s without selecting an employee from the list,
instead of the message "You must select an employee's name from the
list", I get an error message "Invalid use of null". This will
confuse some users - I need for the message in the code to come up.
Any ideas?

Thanks,
JD

Pavel Romashkin <pa************ *@hotmail.com> wrote in message news:<3F******* ********@hotmai l.com>...
I think this has to do with the fact that it is not this line that
finally opens frmVacationWeek s

DoCmd.OpenForm "frmVacationWee ks", acViewNormal, , strSQL

but this one instead:

DoCmd.OpenForm "frmVacationWee ks"

and it does not pass any parameters to the form as it is being opened.
Try putting your password code in the main code module, but make sure
that "password" text box is also the part of the main form:

Dim varSelected As Variant
Dim strSQL As String
Dim bGotPwd as Boolean
bGotPwd = (Me!txtPassword = "password")
If IsNull(Me![EmpList]) Then
MsgBox "You must select an employee's name from the list.",
vbExclamation, "NOTE"
Else
For Each varSelected In Me!EmpList.Item sSelected
strSQL = strSQL & Me!EmpList.Item Data(varSelecte d) & ","
Next varSelected
If strSQL <> "" Then
strSQL = "[Employees].[EmployeeNumber] IN (" & Left(strSQL,
Len(strSQL) - 1) & ")"
if bGotPwd then _
DoCmd.OpenForm "frmVacationWee ks", acViewNormal, , strSQL else _
MsgBox "Sorry, bad password"
End If
End If

Good luck,
Pavel
"jd****@yahoo.c om" wrote:

In Access 97, I have a form named frmEmpList with a list box that
contains the names of all our employees. I have a command button with
the following code in the OnClick event so the form will open showing
only the record of the employee selected from the list:

Dim varSelected As Variant
Dim strSQL As String
If IsNull(Me![EmpList]) Then
MsgBox "You must select an employee's name from the list.",
vbExclamation, "NOTE"
Else
For Each varSelected In Me!EmpList.Item sSelected
strSQL = strSQL & Me!EmpList.Item Data(varSelecte d) & ","
Next varSelected
If strSQL <> "" Then
strSQL = "[Employees].[EmployeeNumber] IN (" & Left(strSQL,
Len(strSQL) - 1) & ")"
DoCmd.OpenForm "frmVacationWee ks", acViewNormal, , strSQL
End If
End If

What I'm trying to do is password protect frmVacationWeek s. I made a
Password form to prompt for a password with an unbound text box and
the following code in the OnClick event of a command button:

If Me!txtPassword = "password" Then
DoCmd.OpenForm "frmVacationWee ks"
DoCmd.Close acForm, "frmPasswor d"
Else
MsgBox "Incorrect Password", vbOKCancel
End If

Here's what happens - I have frmEmpList open, I select an employee
from the list, click the command button, and frmPassword opens. I
type in the correct password, frmPassword closes, and frmVacationWeek s
opens, but instead of showing the employee I selected from the list,
the first employee in the list shows. So, in effect, frmPassword
"interrupts " the code in the OnClick event of frmEmpList. How can I
modify the code so I can accomplish what I want to do?

By the way, I don't know a lot about VBA - someone helped me with the
code above. Thanks in advance for your help.
JD

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1745
by: pmud | last post by:
Hi I have a website (ASP.NET project using C# ) which is already put up on the server. I need to make some modification to some web pages.So the project files were copied to the a different server where I could modify tha pages. But when I open the .aspx pages with Visual studio.net, then I just see the HTML code & no design view of the page. How should I edit the page when in Visual Studio I cant see the design view. Just in case...
0
422
by: karenmiddleol | last post by:
The following code works fine I can connect to a SQL database and list all the records in the Orders table onto a web page. Now our users want me to modify it so that each row displayed as a button or a hyperlink for Modify, Delete and also they want the data displayed not in a HTML table as I am doing but like in a form they want the ability to change the data in the fields. So when the user clicks on the modify button for a row then...
12
2372
by: Michael B Allen | last post by:
Is it legit to modify static data like the following code? #include <stdlib.h> #include <stdio.h> struct tbl { int i; char *s; };
12
1736
by: SStory | last post by:
Doing pages for contract..... If I make an ASPX file that does certain things, how simple would it be for a person who know nothing about it to modify the user interface without bothering the ASPX interaction? How would I best build such pages. Many people of course don't want a page that they can't modify at all without programmer intervention. I think ASPX does this. Just curious to hear some comments on the subject from more...
5
4481
by: Martin Bischoff | last post by:
Hi, is it possible to modify the values of a SqlDataSource's select parameters in the code behind before the select command is executed? Example: I have an SqlDataSource with a ControlParameter <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:XYZ %>"
4
2816
by: mimasci | last post by:
Hi, I have tried to write a code that allowed me to modify the value of the cells selected in a table, with excel has been easy. How one approaches selected cells? (To modify the value) How can I translate the code, in MS-Excel, below in a equivalent code in MS-Access ........................................................................................... Sub convSelExtPIDToShortPID()
1
7446
by: TimEl | last post by:
Hi. Using Perl, I want to modify data in an XML file and print out the entire modified file, not just the elements I modify. In CPAN I have found that XPath allows me to pinpoint the elements that I want to modify. But all of the code examples that I have seen assume that I want to assign the targeted elements to variables, modify each element, and then print only the modified elements out to a file. For example, this code is found at...
23
2005
by: no1zson | last post by:
I have been adding buttons to my GUI to manipulate list data. I added a Delete button this morning in case I decide I no longer needed a particular element. I am now working on a modify button, in case I want to keep the element, but only modify a field or two. This seemed easy after my Delete, but now I am having issues with it. Is there a listModel command out there that I am unfamiliar with that will help me with this? Right now I have...
7
2568
by: Boki | last post by:
Hi All, I want to change WindowState of form1 from form2. I tried these two methods, but no luck on both. (1) Declare a public method: /* function of form1 */ public void active_this_form()
1
1333
by: vijay1012 | last post by:
How to write code to modify a record. One way is using modify, for example $sqlSession->EditEntity( $objtoedit, "modify" ); But for some reasons i should not use this modify. Is there any way to write a code with out modify.
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10077
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9150
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5521
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.