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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Option Menu

Status
Not open for further replies.

MrM121

Programmer
Joined
Aug 21, 2003
Messages
83
Location
GB
Hi, can anyone suggest any ideas for a possible option page? I need to be able to allow the user to select which controls appear on a form, for data entry purposes. Ideally, I would like this to be a menu that can be run from the startup screen, and the values are stored in a table. This is so that the preferences are saved for the next time they open the program.

How could I use this information for determining whether controls appear when a form is linked to another table?

Any suggestions as to how to accomplish this function are greatly appreciated.

Thanks,

Nick
 
Hi Nick!

You will need some way for the user to log in so the system knows who it is. For now I will assume that you have security and can use CurrentUser.

Create a table with the fields fldUserId (which will be filled automatically using CurrentUser), fldControl1, fldControl2 etc. Of course you will want to find a way to identify each field for example:

for a name field you would use fldUser in the table, chkName on the option form and txtName on the form they need to access. All of the fields will be y/n fields.

Create a series of check boxes on the option form for each control the user may want to see. Create a button labeled Save Options and in the click event of this button you can use the following code:

Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("YourTable", dbOpenDynaset)

rst.AddNew
rst!fldUser = CurrentUser
rst!fldControl1 = chkControl1
rst!fldControl2 = chkControl2
etc.
rst.Update

Set rst = Nothing

Of course you will need to adjust this to look for existing records if you want to all the users to change their options.

In the open event of the form that the user needs access to you can put this code:

Dim rst As DAO.Recordset
Dim strCriteria As String
Dim strControlName As String
Dim fld As Field

strCriteria = "Select fldControl1, fldControl2, etc. From YourTable Where fldUser = '" & CurrentUser & "'"
Set rst = CurrentDb.OpenRecordset(strCriteria, dbOpenDynaset)

For Each fld In rst
strControlName = "txt" & Right(fld.Name, 4)
Me.Controls(strControlName).Visible = fld
Next fld

set rst = Nothing

Of course it looks like I have assumed that every control will be a text box but I would recommend that you name each control with the same first three letters no matter what they are. If you don't like txt then use ctr for control or something similar.

hth


Jeff Bridgham
bridgham@purdue.edu
 
Fantastic, that is exactly what I want. I was considering doing it that way, but my only concern is compatibility with previous versions of Access (95 and 97). The program has to be distributed to 33 buildings, so I am wondering which DAO reference would be best, 3.6, 3.5 or earlier.

Nick
 
Hi again!

I haven't used 95 in ages but either of the object files should be fine in 97.

hth


Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top