Calling A Query Thru VBA
Jun 19, 2005
Hi All
Nice to find a forum which helps ppl new to VB access 'like me' :). I appreciate any help in this regard.
I generated a report from a query. I would like to modify this report by adding parameters pertaining to 'another' query (say query num 2). There is no relationship between these two queries. How do I call the 'other' query (query num 2) thru VBA and modify its parameters.
Thanks alot in advance
View Replies
ADVERTISEMENT
Jan 26, 2006
Hi,
I'm having problems calling a simple query from the VBA associated with one of my forms. The code goes thus:
Private Sub Form_Current()
Dim rs As Recordset
Dim db As Database
Dim qryMaxAlp As QueryDef
If Me.NewRecord = True Then
'query database here and find out next alp_key
Set db = DBEngine.Workspaces(0).Databases(0)
Set qryMaxAlp = db.QueryDefs("qryMaxAlpKey")
Set rs = qryMaxAlp.OpenRecordset()
Else
End If
End Sub
The problem occurs on Set qryMaxAlp = db.QueryDefs("qryMaxAlpKey") where I get the error "3265 Item not found in this collection". However the query does exist, and when I run it independantly works fine (it brings back the maximum primary key of a linked table.
So, what am I missing?
View 2 Replies
View Related
Dec 1, 2005
Hi,
In the query field i am putting: -
Consecutive Months: Query_Month_Consecutive([Report_2_group_data].[Availability], array([Monthly_availability_CT].[12],[Monthly_availability_CT].[11],[Monthly_availability_CT].[10],[Monthly_availability_CT].[9],[Monthly_availability_CT].[8],[Monthly_availability_CT].[7],[Monthly_availability_CT].[6],[Monthly_availability_CT].[5],[Monthly_availability_CT].[4],[Monthly_availability_CT].[3],[Monthly_availability_CT].[2],[Monthly_availability_CT].[1]))
Basicly the values of them fields are entered into the query, all fields exist and everything is ok.
Anyhow the function is not loaded, i have tested with a simple msgbox and it does not do it.
However when i simply do
Consecutive Months: Query_Month_Consecutive([Report_2_group_data].[Availability], Monthly_availability_CT].[12)
It works and the msg box appears?
I really need it to be an array for what im doing any help would be great
Thanks
k0r54
View 3 Replies
View Related
Jan 17, 2007
Hi,
My situation:
A front end written in Access (back end mySQL).
I have made a .mde file out of this front end.
There are a number of MS Word documents used (as merge documents) for running reports and letters that are linked to queries in the database. However, I can only link these documents to the original .MDB file as you can't link to the queries ni the .mde file.
This works fine until you have a query that requires a parameter from a form. The user will have selected the parameter from the .mde version of the front end that they are using but the query which is being called from the .mdb version (by the Word merge document) can't see this parameter because it is a totally separate database.
How can I get around this problem?
Sorry this is a lengthy post, hope it makes sense.
Matt.
View 4 Replies
View Related
Jun 29, 2005
I this is a simplifed version a saved query called "qryTest"
PARAMETERS [gUserID] Long;
SELECT [Id],'Complaint' AS IncidentType FROM tblComplaints WHERE tblComplaints.[Id] IN (Select Incident_ID from tblNotification where Dept_ID IN (Select Dept_ID from tblUserDepts Where User_Id = [gUserID] ) AND Incident_Type = 'Complaint');
UNION ALL SELECT [Id],'Fall' AS IncidentType, FROM tblFalls tblFalls.[Id] IN (Select Incident_ID from tblNotification where Dept_ID IN (Select Dept_ID from tblUserDepts Where User_Id = [gUserID] ) AND Incident_Type = 'Fall');
how to i call the result from code or from the query manager and include the parameter so there is no prompt that comes up?
like
Me.ListNew.RowSource = "qryTest " & gUserID &";"
or
Select * from qryTest , 31 - where 31 is the value fed to the parameter
??? does anyone know? I know it can be called in APS like this:
Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open strConn ' strconn is my connection string
set rsP=createobject("adodb.recordset")
conn.qryTest 31
.....
I can't believe I can't do it from the query string!
Heeeellpppp!
View 3 Replies
View Related
Nov 17, 2004
Hi all,
I have quite a large select query that pulls in Date values from different tables. The end result is a list of records, where each record has 7 types of dates, put in columns A, B, C, D, E, F, G. What I need to do is, for each record to compare dates in those columns and put the LATEST one of them in the column MDATE.
I've tried using IIF function, but it grows exponentially with the number of values involved, and it can only handle 5 values before its cause error "too large". Alternatively I thought I could write a function to return the max date and call it from within the query, something along the lines of "select *, fnMaxDate(A, B, C, D, E, F, G) as MDATE from tblBLAH etc". The function is:
----------------------
Public Function fnMaxDate(a As Date, b As Date, c As Date, d As Date, e As Date, f As Date, g As Date) As Date
Dim Temp As Date
Temp = Nz(a, "01/01/1901")
If Nz(b, "01/01/1901") > Temp Then Temp = b
If Nz(c, "01/01/1901") > Temp Then Temp = c
If Nz(d, "01/01/1901") > Temp Then Temp = d
If Nz(e, "01/01/1901") > Temp Then Temp = e
If Nz(f, "01/01/1901") > Temp Then Temp = f
If Nz(g, "01/01/1901") > Temp Then Temp = g
fnMaxDate = Temp
End Function
----------------------
I've put a break at the start of the function, to see what it'll come up with but when running the query it didn't appear to call it. All values in MDATE where #error.
Can someone advise me, please, on the best way of picking the LATEST date? I'd also appreciate it if you tell me why the function didn't get called, as I was quite certain it is possible to call user defined functions from within the query.
Cheers,
Kat
View 1 Replies
View Related
Jun 22, 2005
This is my first time using access and got it to work for a blank database.
The problem I ran into is how do I call for the form in the database from my desktop
I tried a shortcut but it does bring it up but i still have to click on the form to open it
Is there a way to make a shortcut on my desktop to open the form
THXS Steve
View 4 Replies
View Related
Jul 13, 2006
Hi. I am creating a contact management database. Also I am new to Microsoft Access. How would I create a calling history record for each of the clients in the contact database? What would be the best way and how would I go about it? The calling history ideally would include the call recipient, time, date, subject and notes. Thanks. Take care.
View 1 Replies
View Related
Jun 30, 2005
I have a series of IF statements that check my fields and if null call a message telling the user a value must be filled in before the record cab be saved. The code works fine. Here is the code for two fields to show the syntax:
If Len(Me.FName.Value & "") = 0 Then
MsgBox "You must enter a value into FName."
Me.FName.SetFocus
ElseIf Len(Me.LName.Value & "") = 0 Then
MsgBox "You must enter a value into LName."
Me.LName.SetFocus
This same code repeats for each field.
Here is my problem. I have Home, Work and Cell phone fields. The client may not have these numbers. I want to add code that add code for these fields that calls a message box with 2 command buttons(yes & no) with the Message" Does the client have a Home Phone?"
The user would choose the yes or no command button. If the user chooses yes then the same code as above would be called. if he chooses no the ElseIf statement would be called. Can this be done? I don;t know how to wriye the code for the command buttons. can anyone help?
View 14 Replies
View Related
May 4, 2006
Hello.
I have a database that runs a fews tasks for me me when no one is in the office as the systems are quicker and the admin work tedeous and boring, yet necessay. The problem Im having is in calling a database. The problem stems, i think, from the names on the folder. Unfortunately renaming isnt an option because its got many hundreds of users on the server and I dont have the admin rights besides.
The error is coming on .......
Call Shell("msaccess u: eam-shared-dataRes. SalesOutsourceOutsource_DbsDatabase_StoreOutso urce.mdb").
The error message I get says that u: eam.mdb isnt valid .... when its not. The error is caused presumably by the " - 's " and probable after it passes this the " Res. Sales" will cause an error too. So my question Im asking is, is there anyway to make the path read in full, I've tried preceeding with < and ending with > and "" or even ' but still no joy. Can anyone please help, its getting annoying now. :o :confused:
View 5 Replies
View Related
Oct 21, 2006
Hello, I have a VBScript that when clicked on opens the command prompt and fires code to upload a query to my website.
What I would like to do is place a command button on my form that will call the script to run instead of having to go and click on it.
I have searched, maybe using wrong terms, but havent been able to get the right code to do this
any help to call this script from a command button would be appreciated.
View 2 Replies
View Related
Aug 10, 2007
Dear Access Chart Expert
I have been trying to figure out how I can make the x-axis show month abbreviation names instead of numbers. Please see attached gif.
Currently, I use the Month([DateField]) function to get numbers of the month because if I use Format([DateField], "mmm") to get "Jan, Feb, March" the chart sorts the months in alphabetical order instead of the correct monthly order.
How can I be able to use the Jan, Feb etc... labels and have the chart sort them in the correct month order and not alphabetical order?
Thanks so much...
greatly appreciated.
View 4 Replies
View Related
Oct 4, 2005
I need help...
ok, what i have is a table with all the fields, comp_id, Yr,Values
i need to put 2 combo boxes coz the user needs to choose bet. 2 years and get the difference of the value within each yr. I got this part already but my problem is, i need to do a report and what i need to do is everytime the user chooses 2 yrs. the report should come up showing the difference of 2 yrs and the comp_id and type under each yr plus the difference of there values.
*note i already did the whole report including yr, comp_id,data_type*
Im just having a problem in the form structure..
am i exmplaing this clearly?
Pls help..thanks
View 1 Replies
View Related
Oct 5, 2004
Can anyone tell me how on a macro to call another application. I am trying to open up a mainframe session so need to run something like c:mainframe.rsf???
View 3 Replies
View Related
Oct 25, 2004
I want to call a selfdefined subroutine "update()" in several reports. But whenever I try this, Access gives me an Error 2465. The Report is selected dynamically by the user and should adapt itself to other settings made by the user. Can anybody help me how to do this? Thanks.
View 4 Replies
View Related
Jun 7, 2012
I have created a module with a function that capitalizes the third letter in words that begin with "Mc". I have a table with the city field all uppercase letters. I created an update query that takes the field and correctly changes it. How you would go about tying this function to the textbox on the input form. So, if a user incorrectly enters "mccoy" in the City Field the function would be called and would automatically change it to "McCoy".
View 2 Replies
View Related
May 3, 2012
I am trying to run the batch job from the command line. I created AutoExec macro in the mdb(msaccess 2007) which is calling someMainMethod() . How can I pass batch job id to the mdb?
View 4 Replies
View Related
Mar 5, 2008
Hello,
I am having a heck of a time getting a Dell laptop with a WIRED connection to connect to an Access 2007 database.
After foolishly connecting to this database wirelessly, I took the wise advice of members here to never connect an Access database using a wireless connection due to Access' fragility.
But now, even when this laptop is wired to the network, it takes a VERY long time to reach the database. And lately, it fails to connect due to a network failure.
The database is hosted on a Windows Vista Home Premium OS. Two other XP SP2 machines can see and connect to the database perfectly. But this laptop (also Vista HP) cannot see/connect to the database.
I'm totally stumped! I have no idea as I'm not really sure about Vista. I know that Home Premium has much better network access than Home Basic, but this type of simple connection shouldn't be so burdensome.
Has anyone else had this problem? If not, can anyone suggest a route to take ?
Thank you for your time!
Mike
View 5 Replies
View Related
Jul 27, 2005
How do you use a button on a form to call another access program? We have 8 access programs that we want to be able to call from one form.
Thanks
View 2 Replies
View Related
Mar 21, 2006
Hi. I have spent ages searching, but I can't find anything relating specifically to what I want to do, and I'm simply not experienced enough to make up the code as I go along.
I want to call a value from a field in TableA to a textbox on a form bound to TableB. I know, its probably simple, but I can't figure it out.
Any help would be greatly appreciated.
View 13 Replies
View Related
Jun 9, 2006
I have a form, Salesperson, that has a subform Salesperson_SalesGraph. The SalesGraph subform is a pivot chart.
I'm having problems with trying to access items on the subform. The weirdest part is that it seems to work if i call the event from form_open, but doesn't work if i move the code to form_current. This won't work for me, as i need the function called whenever i change rows.
The error received is: You entered an expression that has an invalid reference to the property Form/Report.
First I had the code on the main form, accessing the chart object on the subform but was getting errors that i couldn't access the form property in the assignment, Set objChartSpace = Me.salesperson_salesgraph.Form.ChartSpace (i tried a number of differnet ways, with !'s, with Forms("SalesPerson_SalesGraph), etc.
Then i moved the code to the subform and now i'm just trying to call the publically declared sub with the line:
Forms!Salesperson!Salesperson_SalesGraph.UpdateLeg end
or
Me.Salesperson_SalesGraph.Form.UpdateLegend
The subform has a sub declared as:
Public Sub UpdateLegend()
Any thoughts?
View 3 Replies
View Related
Aug 26, 2004
When I click a button, I am creating a table for a mailmerge and then calling the document that merge is in so I can write letters.
Everything works properly except the line for calling a document. I've messed with it in several ways but right now it tells me I need an equal sign. Can someone who actually knows VB (I'm just pretending! ) look at this and tell me what might be wrong?
Shell("C:Program FilesMicrosoft OfficeOffice10WINWORD.EXE", "\documentsOfficesJudicial & Court ServicesJudicial CollegeShared Project FoldersTemplatesLetters & AccessoriesConf Letter Mail Merge.doc")
Thanks!
View 14 Replies
View Related
Oct 2, 2004
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
View 1 Replies
View Related
Jan 4, 2006
Is there a way to call a function stored in a module in the back-end access file from within a form in the front-end access file?
I want to be able to slip in a change to the code, and not have to then copy the changed module out to every front end file.
I am thinking that this is something that is in fact trivial to do, but for the life of me, I am drawing a blank on how to do it. Or even what search terms to use to search the help files.
Any help is appreciated.
Thanks,
David
View 3 Replies
View Related
Jan 14, 2015
Imagine I have two subrountines:
Code:
Private Sub DoSomething1()
[Do Something]
End Sub
Private Sub DoSomething2()
[Do Something]
End Sub
And this Declaration:
Code:
Dim str As String
str = 1
Is it possible to refer to/call one of these subroutines using something like this:
Code:
("DoSomething" & str)
View 1 Replies
View Related
Oct 29, 2014
I have been tasked to create a multi-keyword search form, however, my form isn't working right and only the first record of the table is opened.
Code:
Public Sub txtSearch_AfterUpdate()
Dim strWhere As String
Dim strWord As String
Dim varKeywords As Variant
Dim i As Integer
Dim IngLen As Long
[Code] .....
These are the codes that I am using for my search form. I have a feeling that I am not calling the variable from the after update portion the right way.
View 14 Replies
View Related