Public Variables, OpenArgs And Compatability Issues
Aug 10, 2005
Hi all,
I seem to have encountered a strange problem at work.
I declared a public variable for user department. The user selects his department from a Log On form and if the password is correct, he opens another form with the department variable passed on in openargs.
All of this works fine in access2k but upon testing with 2003, the openargs somehow do not seem to be being passed on. Maybe I am being dense somewhere but it is kinda puzzling for me.
I am not using access's security for users and groups because I am trying to reduce the complexity of the whole project (I wont be around to maintain it next time).
I'm into one of the subforms that will be using the public variable from the main form and am not having success passing the data from the main form over. on the subform, i created a textbox (txt_currentyear) w/ this in the control source field: =[WrkYear] & " Golf Outing"
WrkYear was the defined in a module as: ********** Option Compare Database Option Explicit
Public WrkYear As String **********
I have created a listbox w/ a few years in it (current_year_listbox). this has =[WrkYear]=Me.Current_Year_listbox.Value in the after update field. i loaded the main form, selected the year, went into the subform to see if it passed the data along w/ no luck.
do i need to call or reference that module in every form or report before i can use the data from it? right now, i just get an empty field on the subform.
It just occurred to me that I use certain variables in several of my routines. Maybe you've done the same... something like:
Dim db as DAO.Database Dim rst as DAO.recordset Dim qdf as DAO.QueryDef
Now, if it's re-used in many routines, wouldn't it make more sense to make it a public variable, and set them to whatever you need it for a certain routine? Would it be more efficient than having to re-initializing and discarding it for every routine that used it? What problem would one expect from making them public?
Also, since it's very common to set db = CurrentDb, would it also make sense to set it publicly, and for cases where you aren't using CurrentDb, use a private variable just for that one?
Is there any way of opening recordsets as public or global in a form? E.g. if i do something like
Set rs = db.OpenRecordset("TblCustomers", dbOpenSnapshot, dbReadOnly)
the variable rs should be available in all the private sub i have on that form, and i should be able to access records without opening database/ record sets for individual subs.
I would like to declare Global or Public variables from a table so they can be added to or edited easily. I had the following function to do this with Alpha Five but at the moment my lack of knowledge of Access VBA is making this task difficult.
Here is the function that I use in Alpha:
FUNCTION udVars AS A (udTabName AS C ) dim codeStr as c t=table.open_session(udTabName,file_ro_shared) t.fetch_first() while .not. t.fetch_eof()
[Code] ....
It opens a table reads in the records and then makes them into a string the string would look something like this:
"Public EuroRate as Single = 0.885"
I would then need to use this string to declare the variables but not sure what command to use - I was looking at the Eval function last night but couldn't get this to work...
The table would hold strings for all the above so you would have:
My_Var (variable name) My_Typ (type of variable e.g. Single) My_Val (value e.g. 0.885)
The table would hold as many variables as required, some would be dates, some paths for making directories and some would be numbers.
I have a table with only two fields and one record: BegDate and EndDate (beginning and end date of the reporting period respectively). I also made a function with variables that look up those values for use as a date parameter in a query.
Here is the code:
Option Compare Database Option Explicit Public Function getCurrentRepDates() As Date Dim dtBegDate As Date dtBegDate = DLookup("BegDate", "tblCurrentRepDates")
[Code] ....
I am getting a syntax error for the line marked red. How can I use "Between" function in VBA code? Access 2010
I've read about 50 posts regarding passing a value from one form to another, and I Just don't get it!
I have a table of zipcodes which I use to autofill city and state fields. The Zipcode is entered into txtCoZip. If the zipcode is in the table it autofills, but if the zipcode is not in the table, a form opens to add it to the table. OpenArgs seems to be the answer to this, but I can't quite follow it all the way through. This is the code I'm using to open the form:
I have 2 form (Form1) is a log-in form, (Form2) is the Data Entry. After Authenticating the user on Form1 I used DoCmd.OpenForm "MyFormName", , , , , , varUserName, then open Form2 with following code on OnOpen event:
If Not IsNull(Me.OpenArgs) Then Me.txtUser.Value = Me.OpenArgs Me.Requery Else MsgBox ("Null") End If
Hi all, I have a form (sub_Main) that opens and has an openargs value (Department) from my main form when user clicks on a cmd button. However, if I were to go back to my main form and click on another department the openargs value is not passed along. I have tried using Me.Refresh under LostFocus but it doesnt seem to work.
What is causing the openargs value from updating? Any help?
Dim strStr1 As String strStr1 = Left(Me.OpenArgs, InStr(Me.OpenArgs, ",") - 1) Me.RecordSource = strStr1
And on the Report's On Activate Event I have
Dim strStr2 As String strStr2 = Mid(Me.OpenArgs, InStr(Me.OpenArgs, ",") + 1) Me.txtTitle = strStr2
This should work but it doesn't. The error states that the SQL statement was not found. Of course, without the second concatenated argument and Me.RecordSouce = Me.openArgs everything works fine. Can anybody see where I have gone wrong
I'm trying to make it so that an item can be returned by clicking a command button (cmdReturn) and a form (Returns) will be brought up with the ItemID field already filled in. I'm trying to use OpenArgs but am having problems. At the moment i've got
In the command button:
Private Sub cmdReturn_Click() Dim varItemID As Integer Me.Refresh varItemID = Me.txtItemID If Not IsNull(varItemID) Then DoCmd.OpenForm "Returns", , , , , , varItemID Else MsgBox "No valid item to return", , "Error" End If End Sub
And in the Open Event of the Returns form:
Private Sub Form_Open(Cancel As Integer) Dim varDCount As Integer, varOpenArgs As Integer varOpenArgs = Me.OpenArgs varDCount = DCount("ItemID", "Returns", "[ItemID]= 'varOpenArgs'") If varDCount = 1 Then DoCmd.GoToControl (Me.txtItemID) DoCmd.FindRecord varOpenArgs, , , , , acCurrent Else DoCmd.GoToRecord , , acNewRec ItemID = varOpenArgs End If End Sub
I'm getting this error message: "Run-time error '94': Invalid use of Null"
And the line in bold above is highlighted with the mouse over message saying "Me.OpenArgs=Null"
If an item already has a Return entry, I want it to go to that entry instead of making a new one. ItemID is the primary key in both tables, linked in a ONE TO ONE relationship.
Any help is appreciated, please ask questions if something's not clear. Joe
Hi I have a form with some tabs. Each tab has 2 subforms, of which the 2nd subform is always the same (call it SubformB).
I had it set up before so that the SQL query to run is passed in the openargs property to that that form and this works well.
However, on a tabbed form, each tab opens up Subform B as soon as the page is loaded. Is there a way to pass openargs to SubForm B on each of the tabs so that they all run different SQL queries even though they are essentially the same form ?
The access website says there is a way to use the open arg in combination with the FindRecord method to open a form up to a specified client name. I'm trying to have a macro that asks the user what student they are looking for and then takes them to the form with that name. The reason I can't use a query or something else is because I have macros on the form page that I want them to have access to.
So my question is this.
What's the best way to make a macro that will 1) ask the user for a name input 2) open an already made form 3) take them to a specific record based on the input name
I tried to use something with InputBox and DoCMD.OpenForm but I'm running face first into a wall any time I tried to combine the two.
Ok heres the situation, Ive had to edit a piece of code that worked fine filtering but wouldnt allow me to refresh a subform on the main search form. Now im using OpenArgs to pass the Selected bike ID to a popup form. This bike ID should then be used to filter the pop up form. But i get error 2001 (You cancelled the previous operation) when the code is run. The Code follows:
Private Sub cmdSell_Click()
Dim stDocName As String Dim stLinkCriteria As String
I'm new to VB and am learing slowly with all your great help in this forum.
I'm wondering if its possible to write a Public Function for vbCRLF. I have a field in multiple forms that are all named 'Note'. If I have the following code:
Public Function PubNoteLF() On Error GoTo PubNoteLF_Err
My!Note = My!Note & vbCrLf
PubNoteLF_Exit Exit Function
PubNoteLF_Err MsgBox Error$ Resume PubNoteLF_Exit
End Function
When I run the code I get Compile Error: 'Sub or function not defined.'
Can someone tell me what I'm doing wrong? Its problably something real basic, but I'm stumped. Thanks.
Hi all, I have done a multi user database for a private company (and thanks to all those that helped me out) but now I need to do another database to put onto the Internet so the general public can view it and order the products. Obviously some of the database needs to be private (so I can update records) but some needs to be viewed over the Internet. I would like the general public to be able to view the products over a web page, not download a program to view the database.
I have made the database already so I can pull up a web page (from within access) and order the products - all I need to know is how to do this over the Internet?
I don't expect anyone to hold my hand through this, I just ask if anyone has a link to a walkthrough so I can do this?
Regards, James
PS Have another question - I have 17, 500 records and I wish to add a new Field, how can I change the values of the Field without going thorugh them one by one? e.g If the Record has 'Rarity = U' then I want the 'price' (which is the new field) to equal 1.
I haev a report with 15 sub reports. I have to use Visual Basic to format the sub reports. I know how to do the formatting (see below) but what I would like to do is have one function (Public) that I can pass the subReport name to and have the formatting happen. This would be mush easier to maintain than copying the code below into on_print events of all 15 sub reports.
Has anyone done this and have an example??
Thanks
-------------------------------------------------------------------------------------- Private Sub GroupHeader0_Print(Cancel As Integer, PrintCount As Integer) Dim widthOfBox, startLeftSide startLeftSide = 0.017 widthOfBox = 0.21 Me.ScaleMode = 1 Me.ForeColor = 0 'Repeat the following line of code for each vertical line ' 1*1440 represents 1 inch
' Me.Line (0 * 1440, 0)-(0 * 1440, 14400) 'Draws line at Left Margin Me.Line ((startLeftSide * 1440) + widthOfBox * 0 * 1440, 0)-((startLeftSide * 1440) + widthOfBox * 0 * 1440, 14400) 'Draws line at Left Margin Me.Line ((startLeftSide * 1440) + widthOfBox * 1 * 1440, 0)-((startLeftSide * 1440) + widthOfBox * 1 * 1440, 14400) ' Draws next line Me.Line ((startLeftSide * 1440) + widthOfBox * 2 * 1440, 0)-((startLeftSide * 1440) + widthOfBox * 2 * 1440, 14400) ' Draws next line Me.Line ((startLeftSide * 1440) + widthOfBox * 3 * 1440, 0)-((startLeftSide * 1440) + widthOfBox * 3 * 1440, 14400) ' Draws next line Me.Line ((startLeftSide * 1440) + widthOfBox * 4 * 1440, 0)-((startLeftSide * 1440) + widthOfBox * 4 * 1440, 14400) ' Draws next line 'the 14400 is an arbitrary number to increase the line to the max of a 'section. End Sub
I have a query that I'm working on through Access 2010's design view. I'd like to add a criteria to the query where it only shows results with the employee name column matching a global variable I created that stores the name of the currently logged in employee.
Here's my vba code that declares the global variable and the public function i'm trying to pass as criteria in the query:
Global gbl_loginName As String Public Function returnName() As String If IsNull(gbl_loginName) Then returnName = "test" ' dummy account created for development only Else returnName = gbl_loginName End If End Function
and here's the SQL code from Access's design view:
SELECT [Entry of Hours].WC, [Entry of Hours].[Employee Name], [Entry of Hours].[Set Up Time], [Entry of Hours].[Run time], [Entry of Hours].[Traveler Number], [Entry of Hours].[Entry Date], [Entry of Hours].[Quantity Finished], [Entry of Hours].Notes, [Entry of Hours].WPS,
[Code] ....
when I try running the query, however, I get this error:
'returnName' is not a recognized built-in function name
Is there a problem with using public functions in Access' design view?
Code: Select distinct [tbl_DTP/CTP].id_zlecenia, [tbl_DTP/CTP].Folia_na_lakier_UV, [tbl_DTP/CTP].Wykrojnik, [tbl_DTP/CTP].Makieta, [tbl_DTP/CTP].Matryca_do_tloczenia, [tbl_DTP/CTP].Matryca_do_zlocenia, [tbl_DTP/CTP].kalka, tblGoraZleceniaRoboczeLaczenie.NumerZlecenia from [tbl_DTP/CTP] inner join tblGoraZleceniaRoboczeLaczenie on [tbl_DTP/CTP].id_zlecenia = tblGoraZleceniaRoboczeLaczenie.NumerZlecenia where tblGoraZleceniaRoboczeLaczenie.NumerZlecenia = r1;
Where "r1" is a public variable as string.The variable has value e.g. "10/145" But query can't get this value and all the time ask about value from "r1" :/
I'm trying to get a public function to work within the design view of a query. The function is defined as:
Public Function Percentile_(fldName As String, _ tblName As String, p As Double, _ Optional strWHERE As String = "") _ As Double... ( I can put the whole code if u need it)
Any thoughts about how I can make the Percentile function calculate values according to a GroupBy statement and not for whole data set?
Is it possible to open another database, set a Public boolean variable in a module?
in db1: Open database by Access.Application, OpenCurrentDatabase, setting obj to db2.CurrentProject, loop through main objects
in db2: Public ByPassCloseVar As Boolean is in a module ModLinkTblReview
I have a process that opens up a database runs through all of its objects to get their properties and values. There is a form that is set up on Unload to close the tool if the variable is set to False. When I open the form to get the properties and their values, then close the form, it closes the database. I would like to set the variable to true in order for the database to stay open.
Thought something like this would work: db2.Modules!ModLinkTblReview.ByPassCloseVar = True
Indicates that method or data member does not exist.