473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Simple function sometimes works ... sometimes doesn't ?

I'm having trouble with what seems like a very simple function,
although it's the first I've used in Access so I could have it all
mixed up. It still works fine in forms I designed until yesterday,
but doesn't work in any new forms. Does anyone know what is going
wrong?

I have a module, "DoCSModule" which contains ...

(in the first two lines ...)
"Option Compare Database
Public CurrentProject As String"

( ... and further down ...)
"Public Function ProjKey() As String
ProjKey = DoCSModule.CurrentProject
End Function"

I call using the syntax, "ProjectKey = ProjKey()". In the most newly
designed forms it returns null, even though DoCSModule.CurrentProject
contains the information I need. As I mentioned, it still works fine
when called from the older forms. I wrote the (otherwise unnecessary)
function so that I could reference the Module variables from Queries.

Nov 13 '05 #1
2 1339

DavidGeorge wrote:
I'm having trouble with what seems like a very simple function,
although it's the first I've used in Access so I could have it all
mixed up. It still works fine in forms I designed until yesterday,
but doesn't work in any new forms. Does anyone know what is going
wrong?


did you put it in a public module? Then you can see it from anywhere.
But why you'd declare a connection, which is accessible throughout the
database, as a public variable is beyond me.

Nov 13 '05 #2
DavidGeorge wrote:
I'm having trouble with what seems like a very simple function,
although it's the first I've used in Access so I could have it all
mixed up. It still works fine in forms I designed until yesterday,
but doesn't work in any new forms. Does anyone know what is going
wrong?

I have a module, "DoCSModule" which contains ...

(in the first two lines ...)
"Option Compare Database
Public CurrentProject As String"

( ... and further down ...)
"Public Function ProjKey() As String
ProjKey = DoCSModule.CurrentProject
End Function"

I call using the syntax, "ProjectKey = ProjKey()". In the most newly
designed forms it returns null, even though DoCSModule.CurrentProject
contains the information I need. As I mentioned, it still works fine
when called from the older forms. I wrote the (otherwise unnecessary)
function so that I could reference the Module variables from Queries.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Well, I don't know the solution to your problem (other than compact &
repair the DB - or recreate the form), but, I would suggest that you use
properties instead of functions (even though they act the same, sorta):

(in the first two lines ...)
Option Compare Database
Private m_CurrentProject As String"

( ... and further down ...)
Public Property Get ProjKey() As String
ProjKey = m_CurrentProject
End Property

Public Property Let ProjKey(strValue As String)
m_CurrentProject = strValue
End Property

You can change the Public/Private aspects of the property, depending on
if you want publicly Read-Only (Public get/Private let) or publicly Read
Write (Public get & let).

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQg5V2YechKqOuFEgEQJjZgCfSdPKQA1wu5DBDrrNAOid3A cLibwAn37S
izLra+VpZfE9mr1ZVoNGb80+
=Iymz
-----END PGP SIGNATURE-----
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Brian Sabbey | last post by:
Here is a first draft of a PEP for thunks. Please let me know what you think. If there is a positive response, I will create a real PEP. I made a patch that implements thunks as described here....
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
8
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value...
64
by: Morgan Cheng | last post by:
Hi All, I was taught that argument valuse is not supposed to be changed in function body. Say, below code is not good. void foo1(int x) { x ++; printf("x+1 = %d\n", x); } It should be...
73
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an...
17
by: DanielJohnson | last post by:
how to use the combination function in python ? For example 9 choose 2 (written as 9C2) = 9!/7!*2!=36 Please help, I couldnt find the function through help.
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
1
by: jerry | last post by:
i have written a simple phonebook program,i'll show you some of the codes,the program's head file is member.h . i suppose the head file works well.so i don't post it. here's the clips of main...
20
by: MikeC | last post by:
Folks, I've been playing with C programs for 25 years (not professionally - self-taught), and although I've used function pointers before, I've never got my head around them enough to be able to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.