Modules & VBA :: Open Variable Number Of Queries?

Sep 15, 2013

What would the best way to open a series of queries, if you aren't sure how many of those queries there are? I have the following:

Code:
DoCmd.Close acReport, "SCEFReport"
DoCmd.OpenQuery "ClearTBLQuestions", acViewNormal, acEdit
DoCmd.OpenQuery "Q1append", acViewNormal, acEdit
DoCmd.OpenQuery "Q2append", acViewNormal, acEdit
DoCmd.OpenQuery "Q3append", acViewNormal, acEdit

Which continues as is for 10 or 11 queries named in a similar pattern, then prints a report. However, as the number of append queries is not set (they are generated in a different quantity for different purposes, it's complicated), I am not sure how to check how many there are with that style of name.

View Replies


ADVERTISEMENT

Modules & VBA :: Open One Database Form Another And Pass Variable To It

Feb 19, 2014

I have a button on my main db, that opens a second db using hte following code:

----------------------
'Dealing with external objects, use inline error trapping
On Error Resume Next
Dim appAccess As Object

Dim db As Database
Dim strAppPathName As String
Dim strAppName As String
Dim strTimesheetPathName As String

[Code] ....

This code works great to open the other db, and handles wheter the other db is already open or not, but I cant seem to pass the variable to the other db using the startup switch /cmd.

I suspect if I used the shell method it would pass the cmd , but I havnt found any way to test if the db is already open with the shell method.

How can I pass a variable to the other db when opening it using VBA?

View 10 Replies View Related

Modules & VBA :: Open Another Database And Send Variable Back

Apr 24, 2015

I have code that from DB1 opens DB2 and runs a Function in DB2.

The DB2 function produces a Boolean result that i am trying to get back to DB1 without success. Below is the script.

Sub Test22()
Dim AC As Object
Set AC = CreateObject("Access.Application")
rc = "K:ARSHRAutomation_ProjectsMikeFEDB2.accd b"
AC.OpenCurrentDatabase (rc)
AC.Visible = True
AC.Run "SendVariable"
End Sub

Because i am using AC.Run "SendVariable" i cant find a way to get the value of SendVariable!!

View 2 Replies View Related

Modules & VBA :: Create And Open Variable Folders With Link Created In Access Query

Aug 5, 2014

I am trying to set up something to be able to take me to a folder that holds various forms for personnel. I have a query that generates the link for each person. I have tried to set it up as a hyperlink in ACCESS 2013 and it displays as one but doesn't act like one.

I want to be able to click the link and have it open up a personnel folder for that individual. I can't find a MACRO that I can create to do it. Example of my query is that it creates a link K:Main BreakdownSection BreakdownPersonnel FoldersName and the name is the variable part.

My next problem will be to have it create that folder when we have new personnel arriving.

I would also note that I have not worked with ACCESS in many years and much of what I was able to do with 2002 and 2003 doesn't work with the newer versions of ACCESS.

View 3 Replies View Related

Modules & VBA :: Using Temp Variable To Append Specific Number Of Records To Table

May 29, 2014

I need to extract a specific number of records into a table using a MakeTable or Append command using a temp variable, e.g. TempK&SA. Previously on the forum I was shown how code could be added to the OnOpen function to use a temp variable to select a specific number of records to report. ACCESS does not have the OnOpen function in the design view of a query like in the report. It does allow a SELECT TOP but only with fixed variables or percents (e.g. 25 in the code below).

The beginning code for the make table query (where 25 is the number of records added) is:

INSERT INTO [Output] ( RndNo, PointBiserial, BloomsTax, DateRevised, Exam1, Status, Exam2, Exam3, Exam4, [NCCPAKnowledge&Skills] )
SELECT TOP 25 TestBank.RndNo, TestBank.PointBiserial, TestBank.BloomsTax, TestBank.DateRevised, TestBank.Exam1, TestBank.Status, TestBank.Exam2, TestBank.Exam3, TestBank.Exam4, TestBank.[NCCPAKnowledge&Skills], *
FROM TestBank
WHERE (((TestBank.PointBiserial) Is Null Or (TestBank.PointBiserial) Between [TempVars]![TempPointBiserialLow] And .....

how to modify the code to allow a temp variable to determine the number of records to append to another table would be gratefully received. (This process then is repeated for a total of 7 append tables with different temp variables.)

View 7 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 :: Update Contents Of Variable But Not The Variable Itself?

Aug 20, 2014

I look at a lot of files to see when they were last updated. I wanted to write a generic procedure to manage that so ..

Code:
Public fDate As Variant
Public vField As String
Public vFile As String

'GTSdata
vField = "txt_gts_data"

[Code] ....

What I hoped Me.vField would do is update the date field [txt_gts_data] on my form with the date the file was last saved.

i.e. me. txt_gts_data = fDate

What actually happens is the variable vfield gets updated from "txt_gts_data" to 19/08/2014 then later code falls over because the fieldname is lost .

Me.[vField] corrects itself to me.vField (and does not work)
Me!vfield falls over (cannot find the field vField, not surprising J)

How do I say update the contents of the variable, not the variable itself?

View 7 Replies View Related

Passing Variable - Form Must Be Open?

Sep 21, 2005

I'm attempting to pass a variable from form to form...I'm having trouble doing it...I checked the forum and read a little that the form I'm passing it from must stay open...is this correct? I have my variable as: Public strUserName as String. It does work fine if I leave the form open then I can pass it...

But I want to be able to close the form and still pass the variable...How can this be acheived?

Thanks in advance.
Kacy

View 3 Replies View Related

Open Form And Go To Specific Record Based On Variable

Jun 9, 2010

I have two tables and two separate forms. [ID] is the link between them. (I cannot do a subform in this case).

Form1 displays 3 records

Have control button that goes to Form2 where [id] = NumID (NumID is "long" variable)

Have control button on Form2 to go back to Form1. It needs to go to the same record it came from. I don't want use a where clause (e.g., where [id] = [id]). This works, but the form1 is now filtered. I need all records available in Form1, but I want to go to the record it was on when the button was clicked to go to form1

Example:
Form1, record1, ID=30
Form1,record2,ID = 35
Form1,record3,ID = 40

Select record3,ID=40, then click on button to go to form2 (has where clause where ID=40).
Form2 is filtered and is correct.

Click on button to go back to form1. No Filter. It goes to 1st record (record1,ID=30). I need all records displayed, but need to be on record2,ID=35.

View 4 Replies View Related

Forms :: Variable Number Of Instances Of A Subform

Dec 8, 2014

I have a subform that formats the data in a record in a particular 2D way. I want to use it a variable number of times on a single form. Is there any way to do that? I've tried using CreateControl, but access just says it can't add the controls I've requested -- with no reason given, of course.

View 2 Replies View Related

Modules & VBA :: Set Value To Variable Outside Sub?

Aug 26, 2014

If I set a variable inside of a subroutine, it is set to nothing upon the end of the sub. Can I set a variable outside a sub and set its value, so that you can use it within subs?

View 14 Replies View Related

Modules & VBA :: Sequence Number In Query Use A Starting Number

Sep 20, 2014

creating sequence number in a query using a starting number. For example i want to use the starting sequence number as 5

---SEQNUM---------COLOR-----------
-----5------------------blue--------------
-----6------------------red---------------
-----7------------------orange-----------
-----8------------------black-------------

View 2 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

Modules & VBA :: When To Use Global Variable

Apr 8, 2014

I have an application where several different procedures are run repeatedly every xx seconds to get live updates from a server (different procedures depending which form the user currently has open.) Within each procedure, a separate single procedure is called only if a stored boolean setting is set as true. The setting itself is only changed very infrequently, such as on application startup, but needs to be initially set (i.e. it cannot just have a default of False if it is not set.)Because of this I am storing the setting in a single record table and have a function 'UsingWPilot' to return the boolean value. However, given the frequency that the setting needs to be accessed, and the fact that speed is crucial in the running of the app, I am considering adding a global string variable and modifying the function to look at the variable (possible values 'N' and 'Y') and only going to the table if the variable has not been set.

I have heard various things about how you should never if possible use global variables. My question is: is it faster to use a global variable than to open the table record each time?

option 1 :

Code:

Public Function UsingWPilot() As Boolean
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("rbl_Settings_System")

Option 2:

Code:

Public Function UsingWPilot() As Boolean

Dim db As DAO.Database
Dim rs As DAO.Recordset
If Len(g_WPilot) > 0 Then
UsingWPilot = (g_WPilot = "Y")
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl_Settings_System")

[code]....

View 4 Replies View Related

Modules & VBA :: Object Variable Not Set

Nov 6, 2013

I am just in the middle of writting a little bit of code that will go through each record in a query and export it into a word table. It's in the early stages but all was working yesterday. I've come to it this morning and ran it and now I get an error message;Run Time error 91: Object Variable or With Block Variable not set.

Code:

Private Sub Command15_Click()
Dim MyDb As DAO.Database
Dim rsLogin As DAO.Recordset
Dim ObjHead As String
Set MyDb = CurrentDb()
Set rsLogin = MyDb.OpenRecordset("query here")

[code]....

View 2 Replies View Related

Modules & VBA :: Report Name As Variable

Nov 6, 2013

I have some code that will allow a user to pass to it the name of a report. The code will do various things to that report before presenting it for Preview, opening in Word etc.

At one point in the code I would like to refer to some control or property of the report. If I was to include this directly for one report, I might type:

Reports!Annual_Budget_Report.Recordsource = xyz

But instead of a specifc report, it would be the report as a variable (srReport_Name). However, if I type:

Reports!stReport_Name.Recordsource

The code complains, rightly, that there isn't a report called stReport_Name. The stReport_Name variable is currently set as String. I *think* the answer might lie in the variable type, but I'm still struggling.

View 3 Replies View Related

Modules & VBA :: SQL Query To Set In Variable?

Sep 19, 2013

I have a form in which am gathering information from the user to populate a table(Customer Master List) and at the same time (btn_Copy_Click Event)transferring the info to another form(Case) populating another table(Customer_Call). It is working fairly well, My issue is that before transferring the info I need to run a check(SQL Query) to make sure the customer or actually the Well ID don't exist in the Customer_Call table. I am trying to do this in pieces .....

1) capturing the well_Id in a variable(WellID) in the first form and using that to build the sql string and query the Customer_Call table.

2)once that works place it in a if / else clause to copy or not with appropriate messages

With that I am stuck in step 1

It works up until Set rst = CurrentDb.OpenRecordset(strSQL) the i get Run-time error '3061' Too few parameters. Expected 1.

Code:
Dim WellID As String
Dim strModel As String
Dim strSQL As String
Dim rst As DAO.Recordset
WellID = Forms!f_Customer_Lookup.Well_ID
MsgBox WellID ' testing to see if it picks up the correct box in form
strSQL = "SELECT Customer_Call.[Cus_Well_ID] " & _
"FROM Customer_Call " & _
"WHERE Customer_Call.[Cus_Well_ID] = WellID;"
Set rst = CurrentDb.OpenRecordset(strSQL)
strModel = rst!Cus_Well_ID
rst.Close
MsgBox rst ' Testing to see if the strSQL captured the data
Set rst = Nothing
End Sub

View 8 Replies View Related

Queries :: How To Specify A Variable In A Query

Aug 18, 2013

I have a query that has three fields: 1) Days 2) Bit Size 3) Feet. The Days field has a date range specified in the Criteria that comes from two unbound fields on a form. I have a second query based on the first: Two fields are Days with the Total as Min and Max. Three fields are Feet with the Total as Min, Mac, Avg. One field is Bit Size with the Criteria as a specified bit size (i.e. 6.125). These queries are used on a report, and all data is inputted from forms prior to the report.

The queries work as expected with a specified bit size. My problem is that while Bit Size is normally chosen from a list of sizes, a custom size can be inputted. I am unsure how I can specify the Criteria in Bit Size to be a custom size..? To compound things further, more than one custom size can be used.

A) I need a way to pick out the custom sizes from the first query and B) use them as the Criteria for the second query. If I use VBA, I assume I could complete B) by using a WHERE clause (if the custom size(s) has been defined)...

View 6 Replies View Related

Queries :: SQL INSERT INTO - Use Of Variable

Mar 17, 2013

Public strOldTable,strNewTable as string

OldTable has data, NewTable is empty but with same field structure.

I assign names of tables to these variables and attempt to fill up the NewTable with the data from the OldTable using :

DoCmd.RunSQL "INSERT INTO ('" & strNewTable & "') SELECT * FROM " & ('" & strOldTable & "')

I can find examples of use of the OldTable variable but not of use of the NewTable in this SQL.

View 7 Replies View Related

Modules & VBA :: Send Report With Variable Name

Jan 8, 2015

I use a macro that attaches a document automatically to an e-mail address ready to send this report is governed by a query of which the criteria is " loss order number " this is in a pdf format of which I need if possible

The problem I have is the same pdf file keeps attaching itself to the e-mail no matter which loss order number I select. The reason I think is because the report is called NCR so it is not changing from the previous one. What I think can solve it but not sure and don't know how to do is get the " loss order number " within the report name.

If I just send the report to a file direct it does work as I am prompted for a file name

Can the loss order number get into the file name within a macro/vba

Code:
Name="EMailDatabaseObject
Name="ObjectType">Report
Name="ObjectName">SEND NCR
Name="OutputFormat">PDF Format (*.pdf
Name="To">=[E-mail Address] & IIf(Nz([E-mail Address

View 2 Replies View Related

Modules & VBA :: Setting Variable To Null When It Has A Value?

Jan 21, 2015

I have the following simple variable assignment...

Dim PolRef As String
Let PolRef = Me.Policy_Ref_Num

But when I run my code I get "Invalid Use of Null" and PolRef is set to ""

This field is populated however, so I'm confused to why I cant set my variable to it.

If I don't use a variable and simply have let XXX = me.Me.Policy_Ref_Num then it still wont return the value from the field.

View 5 Replies View Related

Modules & VBA :: How To Get Query Output Into Variable

Mar 15, 2015

I want to get the output of a vba query (only one solution possible) in to a variable but the variable stays empty.

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("SELECT info FROM evaluationtable WHERE evaluation= " & evaluationchoice & " ")
var = rst(0).Value
rst.Close

some explination: evaluation and info are fields of evaluationtable evaluationchoice is a field in an accessform where I can choice a value from the evaluation field

the table is build as this (only two fields) evaluation - info

View 5 Replies View Related

Modules & VBA :: Str Variable In DLookup Criteria

Aug 18, 2013

Why does this work when the text box is used and not when the variable is used directly?

Code:

Private Sub Command61_Click()
Dim strDBName As String
strDBName = getDBName()
Me.Text59 = strDBName
Me.Text62 = DLookup("[ModuleName]", "tblModule", "[DatabaseName] = text59")
'Me.Text64 = DLookup("[ModuleName]", "tblModule", "[DatabaseName] = " & strDBName)
'Me.Text64 = DLookup("[ModuleName]", "tblModule", "[DatabaseName] = strDBName")
'Me.Text64 = DLookup("[ModuleName]", "tblModule", "[DatabaseName]" = strDBName)
End Sub

Text62 returns the correct value
Text64 failes on everyone of the examples

View 7 Replies View Related

Modules & VBA :: How To Construct String For Variable

Sep 10, 2013

I am trying to set the following variable that will be used to create a PDF file in an already existing folder and name the file WorkorderIDddmmyyyy-hhnnss.pdf

The following variable setting creates the filenameddmmyyyy-hhnnssWorkorderID.pdf.

mFilename = "C:RPR AccessPDF Reports Emailed" & Format(Now(), "ddmmyyyy-hhnnss") & WorkorderID & ".pdf"

DoCmd.OutputTo acOutputReport, mReportName, acFormatPDF, mFilename, True

I just can't figure out how to construct it correctly.

Also, is there a way to dynamically create a folder if the folder doesn't already exist? I currently hard code the folder name but would really like to create the folder name based upon some other variable.

View 8 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







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