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
196 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
ID: 35072446
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
ID: 35089887
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
ID: 35097860
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
ID: 35099344
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
ID: 35105021
Thanks for the kind words
I'm just glad I was able to help.

;-)

jeff
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

895 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