View Full Version : Trouble using a public variable in Form record source


TommyB
06-07-2007, 10:52 AM
I've searched through the forums, but have been unable to find help with the syntax for a SELECT statement I have in a Form.

The following general module stores info about a user that logs into the database:

Public Type UserInfo
ViewID As Integer
AccessID As Integer
Active As Boolean
Password As String
UserID As String
UserName As String
SecurityID As String
End Type

Public User As UserInfo


I have a SELECT query in the Record Source of a form that I want to set a condition on the UserID variable. Here is my SQL:

SELECT tblCurrentMonthData.BU, tblCurrentMonthData.Obj, tblCurrentMonthData.Sub, tblCurrentMonthData.Balance
FROM tblCurrentMonthData
WHERE tblCurrentMonthData.PreparerID = User.UserID;

When I try to open the form, I get a dialog box that asks for the parameter User.UserID

I am sure there is some problem with my syntax, I just can't figure in out.

Thanks in advance for any help!!

WayneRyan
06-07-2007, 10:56 AM
Tommy,

SQL can't resolve Public variables.

I've always seen folks make a Public function that returns, in your case,
the UserID.

WHERE tblCurrentMonthData.PreparerID = GetUserID();


Public Function GetUserID() As String
GetUserID = User.UserID
End Function


Wayne

TommyB
06-07-2007, 11:17 AM
Wayne,

That worked perfectly. Thanks for the help!!

--TB

WayneRyan
06-07-2007, 11:21 AM
Tommy,

Glad to hear you have it working.

SQL can resolve Forms!YourForm!SomeField type of references though.

Wayne