Modules & VBA :: Declare / Define Form Variable (Access 2007)

Jul 16, 2013

Is it possible (and how...) to declare a module-specific form variable (or any variable for that matter) at the top of said module, so it doesn't need to be set at the start of each subsequent procedure?

I have a module of code specific to one form with a number of procedures, each one of which requires me to Dim / Set the form variable. It would be much neater if I could do it once at the start.

Code:
Option Compare Database
Option Explicit
Public Sub Populate(lngParameter As Long)Dim frm As Form

[Code] ......

View Replies


ADVERTISEMENT

Modules & VBA :: Declare Variable With NOT Rounding Numbers

Oct 20, 2014

I need to declare a variable (max_nog_leveren ) but that variable may not be rouded or only after 5 digits so as example 15,xxxxx

I am now using it as a "Integer" but that is not working very well..

Code:
Dim iRet As Integer
Dim strPrompt As String
Dim strTitle As String
Dim max_nog_leveren As Integer
Dim strQuery As String
Dim nettohoeveelheid_toevoegen As String

[Code] ....

View 5 Replies View Related

Modules & VBA :: Declare Public Variable And Assign A Default Value

Nov 7, 2013

I want to define a public variable and i am using the following code but it gives me Compile error Invalid outside procedure.

Code:
option explicit
public ABC1 AS VARIABLE
ABC1="FALSE"

View 7 Replies View Related

Modules & VBA :: How To Define A Variable In One Sub Which Can Be Used By Another SUb

May 12, 2014

How can I define a variable which can be used by another Sub and of course the value stored in it?For instance:

Private SUB A ()
DIM A1 as String
A1 ="ABC"
END SUB

PRIVATE SUB B()
PRINT A1
END SUB

View 5 Replies View Related

Declare Variable

Oct 26, 2004

we upgraded to 2003 access. Now in a code getting the msg that I need to
declare a variable for:xlexcel9795
here is how it is in the code. what do I put?
FileFormat:=xlexcel9795

View 1 Replies View Related

General :: How To Define Variable In Form As String Which Can Work With Any Event

Jul 16, 2013

I have a form (Datasheet). I need to define some variable in form as string, which can work with any event. E.G in column "A"on event after update, in column "B" on event after update...

I will try to explain with a simple example : form (datasheet) columns: "A", "B"

on event after update in coulmn "A", I could have some like this:
(variable what I need to define) = 3

on event after update in coulmn "B", I could have some like this:
If (variable what I need to define) = 3 then
msgbox "ok"
end if

Now I try to work around the problem and use another column "c" to keep the value from after update A - but I know that, it's bad solution -Right?

View 4 Replies View Related

Modules & VBA :: Way To Declare Variables In Sort Of Module That Access Uses By Default

Nov 16, 2014

Can't find any way to declare variables in the sort of module that Access uses by default.Having changed the default, I now get 'Option Compare Database' as the first line (previously nothing was there). Adding anything at all in that section, or changing it to 'Option Explicit' has the consistent effect that all the procedure names in the module are not recognised and nothing works.

Variables declared in procedures work only in the procedure even if declared as Public. Can't get a Static variable to work in more than one procedure. However many variables I declare, there are never any in the Declarations list at the top of the Code Window.

View 3 Replies View Related

Forms :: Hiding Ribbon In Access 2007 - Variable Not Found Error

Apr 2, 2013

Code : DoCmd.ShowToolbar "Ribbon", acToolbarNo

Should hide the ribbon. Instead I get a 'Variable Not Found' error.

This should be simple.

View 13 Replies View Related

Modules & VBA :: Scanning Multiple Pages Into Access 2007 Form

Aug 8, 2013

I have been asked to create a database very quickly for a small group that needs to scan multiple pages into an Access 2007 form. They they would like all scanned documents to be converted to PDF and stored on a shared network folder which can be accessed by their group. I have tried several ideas posted but, I have been unable to get any to work correctly. Any sample of working database that the scanning portion is working? I am so involved with other projects right now that I just don't have the time to create a scanning process on the database.

View 5 Replies View Related

Modules & VBA :: Automate Access 2007 Queries With Form For Users?

Oct 18, 2013

I've been using Access 2007 to run queries on a database where we eventually export results as separate Excel spreadsheets for individual clients. The process is quite involved, using queries to change fields from code letters to words and splitting the database up into different client tables, saving the tables under date order and with different client codes.

I now need to pass this role on to colleagues, so need to make everything as straightforward as possible.

I had thought to use a Form as the user interface, with a minimum number of buttons, however I need either the system or the user to amend the date for the initial table, then to use this new table and run a series of standard queries on it, then produce the separate tables.

I don't think I can just use macros behind the buttons, because the database name is changing each time.

I assume some parts will be too tricky to automate - it will be necessary for colleagues to follow instructions instead.....

View 2 Replies View Related

Modules & VBA :: Using Access Recordset As SQL Variable?

Jan 16, 2014

I am trying to create a process which selects a customer's site identifier and uses that to query an Oracle database through an ADODB connection. Which is all well and good until that customer has more than one site.

Here is a simplified version of what I have created:

Code:

'Get site details from current database on basis of company selected on form

Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
Dim RsSites As New ADODB.Recordset
RsSites.ActiveConnection = cnn

[code]....

As I said, this works perfectly when the customer only has one site, but I have failed to find a way to turn a recordset with multiple values into a SQL variable that can be used in the IN clause.

I have attempted to convert the recordset to a string using GetString, but could not find a way to correctly seperate out the records.

View 5 Replies View Related

Modules & VBA :: Possible To Transport Variable From Access To Excel?

Aug 7, 2015

I have some shapes to be automated in powerpoint (Tables, Pictures and Charts). Each and every shape has to be created on basis of some reports (all excel files with a Dyno-Static Filenames: "Some Bond TE 1-29-2015.xlsx", "Scenario Analysis GSB 28th Feb 2015.xlsx"). Dyno-Static Filename: Filename having some part static and some part variable in it.

So I created a table with a list of file names (report names) with wild cards on it. Like "Some Bond TE*.xlsx", "Scenario Analysis GSB*.xlsx". I am opening these files using the following code from Access:

Code:
If Not IsWorkbookOpened(Dir(CurrentProject.Path & "Received FilesFiles" & SlideNshapes!Shape_File)) Then Set SourceFile = Excel.Workbooks.Open
(CurrentProject.Path & "Received FilesFiles" & Dir(CurrentProject.Path & "Received FilesFiles" & SlideNshapes!Shape_File), ReadOnly:=True)

There is no problem in Access Part. Now I come to my current problem. I am planning to have an attachment field (excel file) to store a table layout model identical to the powerpoint table (shape) to be automated.

Suppose:
The powerpoint table is like the following:
Rates Wtd Dur
US2Y 0.34
The Attachment Layout:
Rates Wtd Dur
US2Y =FilepathfromAccess!Sheet1!M24

There are so many cells to lookup on different excel files. The Following are the questions:

1. how to passs an access variable to a formula in a excel sheet?
2. How to refer only the opened sheets in an excel formula?

View 1 Replies View Related

Modules & VBA :: Function To Define Colors

May 1, 2014

I have one color scheme I want to use all through the database I am developing. The next examples have just one color defined, to make it simpler (a dark blue, that I would call B1)

Code:
private sub setlabel()
Dim B1
B1 = RGB (0,52,105)
me.label1.forecolor = B1
end sub

... however this means I have to repeat the color definition every sub, so I thought would be neater to define a function to set my color codes (I have 20 colors).

Code:

Function SetColor()
Dim B1
B1 = RGB (0,52,105)
End function

My objective, is when I'm working in forms, Iwould (ideally) call this function "setcolor" and just write my code for the blue. I tried the examples below:

Code:
Private sub setlabel()
SetColor()
me.label1.forecolor = B1
end sub

[code]...

Again, this is probably some definition of arguments or dimensions that I am not aware oh. How to predefine the colors in a function to give them a "short" code which I can call in any sub in the database?

View 4 Replies View Related

Modules & VBA :: How To Define Accessibility For Different Users

Oct 28, 2014

I have a multi-user database. I would like based on the logged-in user, some buttons and controls in different forms be disabled and the others be enabled.

There is a login form that gets the username; I made also a function to define authorities for users in it.

My plan is that when user enters to the database, on load of the main menu the function calls and disables the defined controls in different forms. I tried to use this kind of codes:

Function User_1()
[Forms]![frmMainMenu].[cmdUpdateDatabase].Enabled = False
[Forms]![frmChooseReports]![cmdOrdersFollowUpReports].Enabled = False
End Function

Function User_2()
[Forms]![frmMainMenu].[cmdChooseCharts].Enabled = False
End Function

But this code only works for the forms that are opened at the moment and if one of them is closed the system gives Error.

View 2 Replies View Related

Modules & VBA :: Define TempVars From A Table?

Sep 25, 2013

I have a table which is formatted as shown:

ID, My_Var, My_Value, Notes

This table holds variables that I want to declare to use throughout my application. I have been told in another thread that tempVars are the best way to do this.

I have written the following code, which works on a limited basis:

Private Sub btnSetVAr_click()
TempVars.Add "udvVar", Me!My_value.Value
End Sub

This defines a single variable on each button press, fine to work out how the code works, but not much use. What I really need to do is when the initial menu screen loads to call a routine to assign all the variables stored in the table using a loop to do this. The idea is to make all variables values easy to edit or add to, rather than have to edit code each time we need to change them.

The variables table holds 14 records so far, such as:

My_Var, My_Value

EuroRate, 0.885
ConDisc, 0.9
MollDisc, 0.8

As well as holding numbers, they hold strings and date values.

So, on loading the initial form, use an event to assign the variables from the table using the tempVar name as the value held in "My_Var" and it's value as held in "My_Value"

View 6 Replies View Related

Modules & VBA :: Merging PDF Docs Using Access 2007

Apr 1, 2015

Any simple code that merges multiple pdf documents that they are willing to share. I don't seem to be able to find anything that works so far.

View 2 Replies View Related

Modules & VBA :: Sending Email With Access 2007

Mar 12, 2014

How would I set up an Outlook email using a list of recipients from an Access table? I'd like to be able to run this from Access 2007 and not Outlook. However, once the email is set up, I'd like to be able to go into the email and add subject, body, etc. before sending the email.

View 5 Replies View Related

Modules & VBA :: Define Current Sub Folder Within Code?

Oct 9, 2014

I am trying to define a path to identify a current folder - I'll try and explain the way the following code works first (and it does work 100%)

The following code identifies folders and sub-folder structures and imports them (their structures and folder paths and filenames) into a DB

It also simultaneously retrieve's any xml docs within those respective folders and imports the XML data into the same database ........ and then moves those folders into a "processing folder" location.

Cool yes, but I can only import the XML doc's at the moment, by hard coding the path (like this):-

path = "C:UsersjeremybDesktopsnapmadXYZ123XYZFILES 0061940"

The code is highlighted as above - in the FULL code below:

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Code Begins:-
Option Compare Database
Option Explicit

[Code]....

View 2 Replies View Related

Modules & VBA :: Error 91 - Object Variable Or With Block Variable Not Set

Jul 8, 2013

Error 91 - Object variable or With block variable not set

I am getting this error telling me that an object variable is not set.

I know which variable it is but when I step through the debugger it sets the variable and all is fine? Issue is that public variable of a class is not getting set when the VBA Editor is not open?

View 14 Replies View Related

Modules & VBA :: Sorting / Object Variable Or With Block Variable Not Set

Oct 3, 2014

This code runs fine the FIRST time, however trows up a message the SECOND time it is run.

The error is on the line ".Range"

I am trying to sort records which have been exported to Excel.

Dim LR As Integer
LR = 5
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set wbRef = xlApp.Workbooks.Add
With wbRef

wbRef.Activate
.Worksheets("Sheet1").Activate
With ActiveSheet
.Range("A2", .Cells(LR, "O").End(xlUp)).Sort Key1:=.Range("C2"), Order1:=xlAscending, Header:=xlYes
End With
end With

View 3 Replies View Related

Modules & VBA :: Constructing SQL To Insert New Records (Access 2007)

Jul 11, 2013

I have a command button on a form which loops through pages on a tab control and constructs an SQL string to insert a new record into a corresponding table (each tab has it's own separate table)

The tables are linked via a common account ID (an autonumber on a separate 'Core' table, the latest record for which is generated earlier in the code; this section creates a linked record in each of the other tables)

I've used a naming convention in each page such that each control name and it's corresponding field name in the destination table are the same (apart from the first 3 characters which I use to identify the control type, i.e. "chk", "txt" etc.)

For one of my pages, the insertion of the new record keeps failing. I've gotten it to work once or twice but only by randomly changing some of the values on the form (checking / unchecking boxes or keying data into random textboxes etc.) But I can't identify why it works sometimes and not others?

The other 3 tabs/pages insert records with no issue, every time.

I've tried debugging but I don't get any error message when I execute the constructed SQL; there are no apparent control violations and all of the relevant fields are correctly named & referenced. The only 'required' field in each table is the common Account ID, which is present, correct & not duplicated, so omitting null / empty fields or passing empty strings / values for the remaining fields shouldn't be an issue (?)

I can only assume it's a problem with a value being passed somewhere but what's stumping me is that on the other pages, it inserts the records exactly as expected (whether data has been provided or not)

Stepping through the VBA, it looks like a record should be inserted - but when I check the table, there's nothing there?

Code:
Dim pge As Page
Dim ctl As Control
Dim strSQL As String
Dim strSQLFields As String
Dim strSQLValues As String

[Code] .....

View 14 Replies View Related

Modules & VBA :: Passing Variable From Excel To Fire Access Query

Dec 17, 2014

I'm running a VBA routine in Excel that loops through a lot of data. As part of the process, I'd like to pass a variable from Excel to an Access database that is open and have it run a query based on that value.

View 4 Replies View Related

Can You Define 2 AutoNumbers In Access?

Dec 5, 2007

Hi,

I am trying to create a db for software change requests. I have defined 3 tables:

PCR - Change request table. This table contains all info on the software bug.
Release - Software release table. This table contains info about the release date, platform i.e. SAP
Sponsor - The person funding for the change to take place. This table contains info on the sponsor such as Name.

I have identified that I need a one-to-many relationship between the tables. For example, A release will have many PCR's. A sponsor will have many PCR's they are funding.

My Primary keys are: PCR Table - PCR_ID, Release Table - Release_ID, Sponsors Table - BPM_ID.

In order to get a one to many (the many being on the PCR table) I have put two foreign keys in the PCR Table (Release_ID and BPM_ID). Both of these keys in thier own tables are autonumbers. From my undertstanding to get MS Access to relate the data I need to set the foreign keys in the PCR Table to autonumbers. Or do I? I do not want to change the primary keys in the Release and Sponsors table to datatype number as this would mean user manual input which I am trying to avoid.

Thanks in advance for the help.

Ket

View 1 Replies View Related

Modules & VBA :: Define Global / Public Variables From A Table?

Sep 4, 2013

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.

View 6 Replies View Related

Modules & VBA :: Load Sub Form From Variable?

Dec 29, 2013

I have a form which load data from variables in record set where i can make insert update and delete i need to load sub form when the form load the problem is that all text boxes in main box load from variable which are in rerecord set and how can navigate using navigation buttons in main form.

View 2 Replies View Related

Modules & VBA :: Variable Retrieving From Another Form

Jan 23, 2014

I am new to access programming.Is it possible to store a variable in one form and then retrieve it to auto fill a field on another form .

I know hot to Dim and store on the same form but trying to retrieve from another form i cant do .

I presume the second form would be something like this OnLoad Variable=forms"customers"customersFK...

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved