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
198 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

696 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