Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create SQL Server-like Procedures in MS Access? 1

Status
Not open for further replies.

mjquixote

Programmer
Oct 20, 2008
2
US
Is it possible to create queries like SQL Stored procedures in MS Access? For example, can you write conditional statements and declare local variables?

CREATE PROCEDURE procname
(
@username varchar(50),
@password varchar(50)

)
DECLARE @IsEnabled bit

IF NOT EXISTS (SELECT * FROM tbl_AdminUsers WHERE username = @username AND password = @password)
BEGIN
SELECT @IsEnabled = IsEnabled FROM tbl_AdminUsers WHERE username = @username
RETURN
END
ELSE
Etc, etc...

If this is possible can someone provide links to tutorials (i've searched high and low and came up with nothing...probably because it's not possible) :(
 
You should be able to do all of this with VBA in a module in Access.
Code:
Public Function ProcName(strUserName as String, strPassword as String) 
   Dim booIsEnabled as Boolean
   If DCount("*","tbl_AdminUsers","UserName ='" & strUsername & "' AND Password = '" & strPassword & "'") > 0 Then
      booIsEnabled = DLookup("IsEnabled","tbl_AdminUsers","UserName ='" & strUsername & "'")
   End If
   Procname = booIsEnabled
End Function
You could also use ADO or DAO recordsets in place of the domain aggregate functions.

Duane
Hook'D on Access
MS Access MVP
 
Thanks. That's exactly what I was looking for. (I actually already started looking in using modules.) The only problem is I can't find much in the way of help or tutorials.

 
Access has some VBA help, but its not installed as standard. You need to do a custom install of MS Office and specifically choose for the VBA help to be installed.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top