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

VBA Code learner Please Help

Hi all I can write basic VBA code.
I have on problem, I have a tbl with the following fields:
lngempID - Name - Password - IN

This is for a logon form once the user logon I want the field IN to
mark the current users as logedon (true)

I need to open recordsets, that I know but have tried everything.
Please Help me!!!!!

On the Main MDIFORM I need a button to log user off and change the IN
status to false.

South Africa
Nov 12 '05 #1
1 1423
First things first, don't use "Name" as a field name, in your case change it
to "EmployeeName". Name is a reserved word in Access and it can cause you
grief later on. Also change the "IN" field to "LoggedIn"

In the logon form use a combo box that lists the users' names so the user
can then select their name instead on typing it. Use 2 columns in the combo
box: lngEmpID, EmployeeName. Set the combo box's column count to 2 and the
column width to 0cm;3.5cm. This will hide the first column and display the
second. Also make sure there is a text box for the user to type in the
password.

Behind the button you're going to use to log the user in copy the following
code.
(I'm using "tbl" as the table name, change this to the actual name of the
table)

' **************CODE START 1 *************************
Dim db as DAO.Database
Dim rst as DAO.Recordset
Dim strSQL as String

On Error GoTo LogInErr

strSQL = "SELECT lngEmplD, Password, LoggedIn " _
& "FROM tbl " _
& "WHERE lngEmpID = " & Me!ComboBoxName & ";"

Set db = CurrentDB
Set rst = db.OpenRecordset(strSQL)

With rst
If .RecordCount = 0 Then
MsgBox "Please select a user"
Else
If !Password <> Me!PasswordTextBoxName Then
MsgBox "Incorrect password", vbCritical
Else
If !LoggedIn = True Then
MsgBox "This user is already logged in"
Else
!LoggedIn = True
End If
End If
End If
End With

LogInExit:
On Error Resume Next
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Sub

LogInErr:
MsgBox "Error # " & Err.Number & " has occured." & vbcrlf _
& vbcrlf & Err.Description
Resume LogInExit
'***************CODE END 1***********************************

To log the person off place the following code behind the Log Off button.

'**************CODE START 2 *********************************
Dim db as DAO.Database
Dim rst as DAO.RecordSet
Dim strSQL as String

On Error GoTo LogOutErr

strSQL = "SELECT lngEmplD, LoggedIn " _
& "FROM tbl " _
& "WHERE lngEmpID = " & Me!ComboBoxName & ";"

Set db = CurrentDB
Set rst = db.OpenRecordset(strSQL)

With rst
If .RecordCount = 0 Then
MsgBox "This user doesn't exist or is not logged in."
Else
!LoggedIn = False
MsgBox "User successfully logged out."
End If
End With

LogOutExit:
On Error Resume Next
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Sub

LogOutErr:
MsgBox "Error # " & Err.Number & " has occured." & vbcrlf _
& vbcrlf & Err.Description
Resume LogOutExit
'*********************CODE END 2 ***********************************

"Mark" <te********@webmail.co.za> wrote in message
news:40**************************@posting.google.c om...
Hi all I can write basic VBA code.
I have on problem, I have a tbl with the following fields:
lngempID - Name - Password - IN

This is for a logon form once the user logon I want the field IN to
mark the current users as logedon (true)

I need to open recordsets, that I know but have tried everything.
Please Help me!!!!!

On the Main MDIFORM I need a button to log user off and change the IN
status to false.

South Africa

Nov 12 '05 #2

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

Similar topics

242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
8
by: ilPostino | last post by:
This question is for long term coders hense the extra posting on c# ;) I find coding for long periods and on big projects frustrating when trying to use keyboard AND mouse. Do any of you use just...
22
by: larry | last post by:
I was just looking at a demo training that mindleaders has on .net training: http://www.mindleaders.com/products/democourse3.asp And I don't believe this is correct or at least is misleading...
6
by: C# Learner | last post by:
In the following two code blocks, DoSomethingUseful throws AnException, while neither of the other called methods throw any exceptions. Which of the code blocks is better (in terms of readability,...
239
by: Eigenvector | last post by:
My question is more generic, but it involves what I consider ANSI standard C and portability. I happen to be a system admin for multiple platforms and as such a lot of the applications that my...
5
by: | last post by:
Hello, I am wrtting a program that does some sound effects... the files are stored in a subfolder in the application folder... and I check the existence of the files before calling the method to...
1
by: bill.wu | last post by:
in this list: mail.python.org Mailing Lists. which one suits for learner. thanks very much.
2
by: 2pot | last post by:
Someone willing to help an ambitious noob learner fix his program? I'll PM to whoever says yes.
18
by: subramanian100in | last post by:
Consider a class that has vector< pair<int, string>* c; as member data object. I need to use operator>to store values into this container object and operator<< to print the contents of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
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...

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.