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

Variable setting itself to 0

Status
Not open for further replies.

aw23

Programmer
Nov 26, 2003
544
IL
I have a simple question but I'm kinda stuck. I have a table with all users and their id. I frequently need userid. Everytime I need the id I don't want to have to do a query useing currentuser (I'm assuming that would tale longer). So I created a public variable UserID and in form_load I call a function which sets this variable and I then use it throughout the application. My problem is that every so often (I'm not sure what causes it to happen which is why I am posting)it is set to 0. This obviously causes lots of problems. Anyone know why or a simple way to get around it? I could call the function everytime I'm just afraid it may slow things down a bit.

Thanks!
 
The only way I am familiar with Public variables losing their value is if there is an unhandled error at run time.

If that's not applicable in your case then perhaps you should run a Find on your code to make sure that it is not reset anywhere.
 
Sorry, it's not really userID, I didn't think that was significant. It's really RepIDLoggedOn
 
Nowhere in all your VBA code a single instruction like this ?
End

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
No, I have a function which sets the varibale. I only call that function once. Other than that I use the variable but never setting it.
 
Ok, I think I got it. I put a break in the code and I added the variable as a watch. when it got to the break the variable was populated. Then I stopped the program and then I ran the program again without reloading, I just clicked a button. I checked the variable and it was 0. Everytime the code breaks it becomes 0? I'm still confused though because a user hd 0 in the middle. Maybe there was an error, it broke, and then it reset to 0? Is that possible? How can I avoid this aside from catching all errors? I am working on that but a lot are not being caught right now (I know, bad programming, it wasn't me, I'm trying to correct it)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top