Variable button label mabye?

RMC

Registered User.
Local time
Today, 15:32
Joined
Oct 29, 2014
Messages
11
I have a printed form that pulls some of its data from a table.
What i need is that printed form to have a variable that two area in the form can change based on who is printing the form.
I have a table that has all the users data in it. the current form pulls that information from the label and places it into the for. easy enough so far right.
So the form prints with:
Tom Hanks
Supreme Leader
for example. But i need this printed form to be able to be dynamic. So for instance Tom inst sitting that the computer wanting to print the form. its Mark Twain... now i need the form to print:
Mark Twain
Steamboat Captain
and so on for four different users who will print the form.
So the button that allows the print either needs a way to have a selection or i need four different button.
So the second part of this Mark Twain quits his job and Johnny takes his place. easy enough to change the data in the table that my form is pulling the data from but the button label needs to change to that the button no longer says Mark but now displays
Johnny
Supreme Leader

So long story short i need a dynamic button label that pull its data from a table with the data i suppose.. i wrote all the rest in case someone has a better brain idea than I
As always, Thanks in advance

EDIT:
I am using Access 2003
 
Last edited:
You can identify your users by their windows logins or computer names. You can use the VBA.Environ() function to return the "Username" and "Computername" on which the code is running. Then it is not that hard to check a table, find the name of the person with that user account, and put that name on the button.

Code:
const SQL as string = _
   "SELECT PersonName " & _
   "FROM tblUser " & _
   "WHERE UserAccount = '{0}'"

dim usr as string
dim usn as string

usr = environ("username")
usn = currentdb.openrecordset(Replace(sql, "{0}", usr)).fields(0)

me.cmdMyButton.Caption = usn
Hope this helps,
 
Thanks for the reply!
However the computer has no accounts and no user login. Just a simple stand alone.

So it has to be easy to update later when i am gone.. even if i had to make another menu button to link to another table that you could input the data into and it would update the printed form(the one that has the names and positions) and menu buttons(the one that prints the just mentioned form.)

If i am being to vague i can go into more detail.

Thanks again
/RMC
 
Does every body use the same computer? You can find the computer name using environ("Computername")
 
Sorry it took so long to get back to this
Ok i have had some time to play around.. i think i know allot more than i did before. been hitting the books and what not.
I think what I am looking for now. On my main form i have a "PRINT" button. i would like that button to bring up a pop-up modal window, we will call it "printchoice". When "printchoice" opens it will allow me to select from four different reports to print. each report is the same with the exception that it will print at the top of the report 1 of 4 different managers (Tom, Ed, Carly, and Thor) based on the button i choose on the main form. the reports that have each different manager are already made and i have four different buttons on my main form, 1 for each Manager.

For additional information, and maybe a better way to-do things:
For the four different managers fields I have a separate table(TblMgr-Info) and a associated form(frmMgr-Info) for the entry of those managers names in fields. In "TblMgr-Info" i have 8 different fields in the table (mgr1, mgr1title; mgr2, mgr2title... and so on) on "frmMgr-Info" I have a text box that is linked to each different fields in "TblMgr-Info".. so when i new manger transfers in and one of the original leaves I can have just update"frmMgr-Info" and now everything down the hill will update to the new manager's information in "TblMgr-Info"
the drawback that i can see is that when i change the manager's information(name) for the "Mgr1" field it will update all the entries previously in my main DB table, forms, and reports..etc.

As far as listing users by their windows logins, that is not feasible in my environment. shared computer and this DB will be used in a variety of different locations.
 
Last edited:
Alright well i have learned quite a bit since this last post and now i see the error in my thinking on how to set this up.

So, now i have a login screen without passwords.
I want to be able to set a variable based off of the id that was selected. pretty simple. the login page pulls from "tblManagrs" in managers i have 2 fields; "Name" and "Title".

lets step back for a sec. the form is all put together and i have my data in. now when i click on the print is pulls up the report. on the report i want it to use the value of who logged in and use that data in the report. both fields.. both fields will be used but in differnat areas of the form. lets say at the top i want the managers name and at the bottom i want the managers title.
So how do i pull that variable data into the report.

ohh and also on the form i want the manager and his title to be put into the table that that the form is working from. so i can track who entered the data into the form later on.


Hey, and thanks for all the support. i know i am probably asking very easy questions for you but scouring the Internets has yeilled what i need exactly. And for those who made videos for reference another thanks goes out to you.
 
Is this a split database - front end back end?
Firstly I would rename your "Name" field, that is a reserved name in Access.
Personally I would add a EmployeeID to you tblManagers. If you have 2 John Smiths managers you won't have any unique look up.....

You need to add a local table call it tblUserLog. It is a one row table with a couple of fields, LogID, UserName, LogInTime etc. You set LogID record 1 with the latest data from your log in form.
Then on your report add an unbound text box, set its control source = dlookup("UserName","tblUserLog"), You can do this on any form you need to record the current user.
 
OK so i did ad a Primary key ID to the tblManagers. you made sense there. the problem i will face with that in the future is if someone goes into the tblmanagers and edits a name to make it their own and will will cascade all the relationshipped (is that even a word..) table's data.

It is not a spit database. that I know of since i don't really know that is. its just a small tracker. will have 4 reports that will print out. very simple. i am over engineering it and learning so that when i make my next one(which will be colossal.. at least from my perspective... but no where near the Northwind Database) i will be well versed and less mistakes that i have to figure out how to undo.

So i am sot sure if it will do this if i go your route. i need it to save that userName data for later reference; in case that report has to be reprinted. Additionally when a different user logs in i don't want their data to overwrite the original users data with their own because they accessed the record to view/reprint.

So here is my train of thought:
OK so for my usage i have tblTrackeditems and tblmanagers In tbltracked items i will make UserName,
So I have my TblTrackeditems and i added a field "UserName" at the end and set it to "text". There is now a total of 6 fields that require data input in the form/table

I have FrmLogin. i have 2 things in that form. a drop down box that pulls the data from the tblManagers. got my drop down cbobox work. Check. i have a Submit button but no controls on it.

So when i select the user in the cbobox then i click on submit (yea i know i am talking at the lowest level of knowledge. but if i am thinking incorrectly in my process hopefully someone can point that out to me)

so Onclick[event procedure]=

Sub ONclick cmdSumbit()
if isnull"[me!UserName]
then
Msg Box "Click on a name, DUH"
Else
'This is where i need code that plugs that data into my TblTrackedItems
End Sub

!!I am a code genius !! :P


It seems easy but since i dont know VBA/SQL coding or frankly any code writing it gets bumpy fast. Used the Access DB templates but they didn't provide as mush help as I thought. I have office365 at home and access 2003 at work with no interwebs

Hey and as always thanks for your help and bearing with a access NUB(Submariner talk for None Useful Body)
 

Users who are viewing this thread

Back
Top Bottom