Solved

how i send to a globel model a string and how i get it back in access 2010

Posted on 2011-03-08
5
193 Views
Last Modified: 2012-05-11
hi

i have in a form this formula

how can i send it to a globel model function and how i get it back from the globel model
Dim strFormName as String
Set strFormName = {Current Form Name}

Open in new window

0
Comment
Question by:bill201
  • 3
  • 2
5 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Technically you don't "Get" or "Send" values to/from a Module.

You typically can retrieve a Public Variable using a Public Function.
...And store values in public variables.

Something like this in a Public Module:

Public lngpubCustomerID as long

Public Function GetCustomerID () as long
    GetCustomerID =lngpubCustomerID
End function

Now you can set the public variable from anywhere in your project, something like this:
lngpubCustomerID =me.cboCustomerID
...Then retrieve it with this:

SomeThing=GetCustomerID()


Note that you may also have to implement a system to "reset" the variable.

The danger here is that you must tightly control where, when and how you set the Variable, or things could get confusing.


JeffCoachman
0
 

Author Comment

by:bill201
Comment Utility
Thanks for Your Answer sorry for the delay i was outside the town...


iry the code that you give but its not working

this is my code in the form that i store the variable
Public Sub Command21_Click()
Dim strFormName As String
strFormName = Me.Name
GetFormNameSt = strFormName
End Sub

and this is my public module
Option Compare Database
Public GetFormNameSt As String
Public Function GetFormName() As String

GetFormName = GetFormNameSt


End Function

and in the other form where i want to retrive the variable i wrote this code in a command buttan
Private Sub Command0_Click()
Dim b
b = GetFormNameSt
MsgBox b
End Sub

but the problem that i get a blank msgbox without the form name  
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
Comment Utility
Your naming is a bit confusing.
It seems like this line:
GetFormNameSt = strFormName
You are trying to assign the value of the variable named strFormName to a variable named GetFormNameSt
But the prefix "Get" is typically used to refer to a *function*, not a variable.
You cannot assign a variable to a function.
A function will "return" a value.

I also don't see the need for the "Intermediate" variables (unless you are using them somewhere else...)

If your ultimate goal is to store the name of a form and retrieve it in another form, then you really only need to reference the public variable:
Msgbox YourPublicVarialbe

But in the interest of completeness (and because you cant use a Public variable as criteria for a query), I will show you both methods in the attached sample

;-)

JeffCoachman




Database47.mdb
0
 

Author Comment

by:bill201
Comment Utility
thanks thousand times for your excellent and detailed answer i'm grateful for you, I'm more than supplied from your professional answer and it is a pity that i don't can to give your more then 500 points...


Bill
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Thanks for the kind words
I'm just glad I was able to help.

;-)

jeff
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now