Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
202 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 2000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

824 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