solve one problem created another

Amy35

Registered User.
Local time
Today, 03:45
Joined
Mar 12, 2002
Messages
53
I was trying to grab the username (LANID) and place it in a text box on a form. I used Pat's code:

Option Compare Database
Option Explicit

Declare Function wu_WNetGetUser Lib "advapi32.dll" Alias "GetUserNameA" (ByVal sUser As String, nBuffer As Long) As Long
Function NetwareCurUser() As String
Dim sUser As String
Dim nBu As Long
Dim x As Variant

nBu = 8
sUser = Space(nBu)
x = wu_WNetGetUser(sUser, nBu)
sUser = Left(sUser, nBu - 1)

If IsNull(sUser) Then
MsgBox "Incorrect logon"
Else
NetwareCurUser = sUser
End If
End Function

Works great but now I am getting an error on every single button I have (or create) (ie..add new ticket, find next, close, print etc.)Here's the error messgae I get:
"The expression on click you entered as event property setting produced the following error: constants , fixed length strings, arrays, user-defined types and declare statements not allowed as Public members of object modules"

I even deleted the buttons and used the wizard to re-create them. Same error occurs.

The LanID text box has the default setting of =fOSUserName() although the form (and error message) seems to run the same with or without that.

Anyone have any ideas on why the new code is causing the error message? the command buttons were working fine til I inserted the code to stamp the Username in the LANID text box. Thanks in advance for any help on this.

Amy
 
Where have you placed this code?? If it is in the code behind the form then I can understand why you are getting that error.

To rectify this move the fucntion code into its own module - don't name the module the same as the function or it won't work.

Repost if supposition incorrect.

Ian
 
Thanks, I thought that might be the problem but because of my ignorance, I was avoiding modules.

2 questions for you....
Any good books you can recommend on Access 2K? and secondly, (if this was IRL, I'd be much more embarrassed). How do you call a module from within a form. I know this is one of those things that is common knowledge or very easy, but I can't figure it out. (I see a place on the form properties called "has module" and I have set that to 'yes'). I'm surprised I've gotton as far with the database as I have. Hopefully you're getting a good chuckle out of this.

So how do you use the modules once you create them? I've named mine modUserNameLookup.

Thanks, I appreciate your help.

Amy
 
Also be aware that if your function is now named NetwareCurUser(), you will get interesting (i.e. wrong) effects if you try to refer to it with fOSUserName().

Good luck,
David R
 
I've used QUE's books on Access to good effect. They're a step above the Access for Dummies books (which are not bad at all when you're just starting out), but doesn't overwhelm you with stuff you don't need right away. It's a big black book with "Special Edition Using Access <version>" on the cover.
The Access Bible is another popular one, however I'm just a hack so that seemed overkill.

Call a function from your form with =FunctionName(). Don't refer to the module name, which really will never matter as long as it doesn't conflict with anything else. Call it PublicModule for all Access cares. You can also refer to public functions from queries, reports, etc.

Post back if you have further questions, and please don't be embarassed. I've even found early questions from Talismanic that he'd probably be embarassed to have see the light of day (much less the question I started with). We all start somewhere.

Good luck,
David R
 
Thanks! I got the system to pull the username and put it on the form! I was beginning to give up hope.

Now I have other problems in that I'm trying to tie the username to the LANID in the database and then pull the information onto the form..Right now it's taking the system's username(LANID), putting it in the textbox and then taking the first record and putting the information from that on the form. So in effect the username and the user information on the form don't match. Not so great since I only want the users to be able to view their records and no one elses. It's always something isn't it? One of these days it will work. Would help if I were more of a programmer by nature.

Thanks for all your help. This forum is a lifesaver.

Amy

p.s. I'm going to check out those books..
 
Not sure what you mean by System's username? Is it putting "Admin" in? I think I have a solution if that is the case.

Also, what version of Windows are you using?

David R
 
VBA for microsoft office 2000 UNLEASHED

has saved my hiney many times

has some good examples and pretty much answers 90% of my questions.
 
DOesn't look like my other post posted..if it did then pardon my double.

I'm running Windows NT.

Guess I was a little confusing. When I said System User Name, I meant the LAN ID the person logged onto the network with.

Thanks to this forum, I have made huge strides today. I got the form to take the LAN ID.. fOSUserName() and put it on the form. I also tweaked the query to make sure the LAN ID... matched the other fields. SO at least that aspect works.

Of course no programming would be complete without another issue! Next week I guess I'll work on having the new record use the user's lan id and match it up with the other fields in the table to put it on a blank form. Compared to everything else that should be easy! Although aren't those always famous last words?

Thanks for your help....have a great weekend..you'll probably hear from me next week!

Amy
 
So this form opens automatically when your database opens? Put the [UserName] field in the query underneath your form and in the criteria: =fOSUserName()

Unless I'm misunderstanding the problem...can you give a concrete example?

DoCmd.GoToRecord .... can be helpful for avoiding seeing that first record by default.

If you're pulling this form up by a switchboard or something, you can put in code for the button:
DoCmd.OpenForm "FormName",,,"Me.[UserNamefield] = '" & fOSUserName() & "'"

If I'm speaking greek at you, just post back and someone will translate.

Good luck,
David R
 
Hi there, hope you enjoyed your weekend. I have my forms working correctly now. Yes the form does open automatically and I took your suggestions and made some changes in the query behind the form (to have the LANID= fSUserName()) then to show only those records (thereby only allowing the users to see their records). I also used the DoCmd.GotToRecord to bring up a blank form instead of that first record (Thanks!).

I'm thinking I've got it all figured out. It's working great the records are getting added and all the buttons are working like they should. Then I go to the other database (This whole project is comprised of 2 databases, one for the users with linked tables (DB2 this is the one I've been doing all the programming in with the fSUsername), and the other database for the support staff (DB1) to view and respond to the tickets. DB1 has the original tables. I go to view today's tickets (in DB1) and they aren't there! They show in the other database(DB2) with the linked tables and the forms. Why isn't the information getting sent to the original tables in DB1. I thought that was the whole point of linking. I wonder if it's the fOSUserName() messing it up. Like I said it's always something. I will need to look further into this. It did work at one time, that's why I think it might be the fOSUserName, somehow that's not syncing with the LANID.

Here's a trick question. You know those infamous max/min/close buttons at the top of each form? Is there a way to hide those so the user can't click on the "x" and then go to the database screen? I'm sure there's gotta be a command for that.

I really need to work on getting this out to the Web with the Data Access Pages. Looks like that requires alot of programming to make it user friendly. Although maybe with that new fOSUserName, I might be closer than I think to getting it to work.

Thanks for all your help.

Amy
 
I can answer your question about the database window: In Tools>Startup there is a checkbox for Display Database Window. Uncheck this and it will disappear for your users. If they're average users this may be sufficient. You can use F11 to get it to come up still, but unless they know this they won't be able to get at it directly. There is also the 'open-Access-while-holding-Shift' technique which bypasses startup options. If your users are more "creative" you may need to click Tools>Startup>Advanced and uncheck the Special Keys. Make sure before you do this that you know how to undo it, or you can lock yourself out. The archives have many posts on 'secur database' (leaving off the suffix allows it to match secure or securing).

As far as linked databases go, I can't answer that one for sure. Are your forms/queries pointing to the linked tables, or perhaps random copies that are local? Are the links going to DB1, or somewhere else? Are the tables/forms in DB! run by queries which are somehow excluding the new results? You may not be able to see new tickets in DB1 unless you refresh the database (try f9, or closing the form/opening it again).
Some of that may help, or perhaps someone else will see the answer. If you don't get a reply today that's probably worth a new topic tomorrow. This one is getting rather long.

HTH,
David R


[This message has been edited by David R (edited 04-08-2002).]
 

Users who are viewing this thread

Back
Top Bottom