Call Fuction From Query Code
Jul 29, 2005
i have a sample function
Function GetPercent(n As Integer) As Integer
Select Case n
Case 1: GetPercent = 100
Case 2: GetPercent = 50
Case 3: GetPercent = 0
End Select
End Function
I have a table like this
a | b | c | d | e | f | percent
----------------------------------------
1 | 2 | 1 | 3 | 3 | 1
3 | 1 | 3 | 2 | 1 | 3
1 | 2 | 1 | 1 | 2 | 1
2 | 2 | 3 | 3 | 1 | 2
1 | 1 | 1 | 2 | 2 | 3
1 = 100
2 = 50
3 = 0
for example the first row
1 | 2 | 1 | 3 | 3 | 1
(100+50+100+0+0+100) / 6
I think if I can call function from query than I write like it:
strSQL = "update table set percent = " & GetPercent(a) + GetPercent(b)
CurrentDb.Execute (strSQL)
but sure that I got an error because its not find the a and b
how can I do it?
good day!
View Replies
ADVERTISEMENT
Sep 12, 2014
I am trying to use a textbox value to call vba code and can not get it to work.
I keep getting an error on the call str1 line.
Code:
Sub formscript()
Dim str1 As String
str1 = [Forms]![fscripts2]![t3]
'MsgBox str1
If str1 = "" Then
str1 = "err1"
Exit Sub
Else
Call str1 ' this is where it call the script based on value in textbox
End If
End Sub
View 14 Replies
View Related
Sep 14, 2005
Any idea how to retrieve the name of the Module and the name of the Sub/Function that currently executing?
Show me the door... :-)
View 2 Replies
View Related
Sep 4, 2013
I'm having to recode some old MS Access DBs so they will run in the following environments:
Office 2000 on WinXP
Office 2003 on WinXP
Office 2010 on WinXP
Office 2000 on Win7
Office 2003 on Win7
Office 2010 on Win7
When I wrote my code for Office 2000 on WinXP things were simple because directory paths were the same across all computers and I could hard code pathing when using a shell command to launch other files.
My new approach is to make a function call to the Windows registry to determine the default executable and path for opening a file based upon its extension (see apicFindExecutable in basWindows API module).
I'm able to use code to create a shell call and debug print it to the immediate window. If I put my cursor in the immediate window at the end of the shell call and hit [enter] the external file will open as desired. If I try to open the external file directly through code, I get a file not found error.
To recreate the error take the following steps:
(1) browse to files that are accessible from your computer
(2) click the PREPARE DATA AND OPEN MAIL MERGE DOCUMENTS command button
Shell function call is made by the fnOpenFile function located in the basOpenFile module. There has to be a trick here that I'm missing.
View 5 Replies
View Related
May 14, 2007
Hi,
I need to build a query where upon form input a different table gets queried.
SELECT *
FROM ((Forms!DCL!PortDropDown))
WHERE ((Forms!DCL!DestinationList=(Reg_Dest.Destination) ));
The "FROM" is my problem. The "WHERE" is working. I am getting a "SYNTAX ERROR IN JOIN OPERATION" error message. Please help.
Thank you:confused:
View 6 Replies
View Related
Mar 14, 2013
I want to track which user has which phone and track issues with them.
I have all the relationships set up right.
I have tables:
DeviceStatus - for the drop down box, contains IT Stock, Faulty, With User and Retired
DeviceTypes - Contains model numbers for devices
Assets - Contains a link to DeviceTypes, a link to DeviceStatus and the serial number of a phone.
I have a query:
StockStatus - shows Assets.ID, DeviceStatus.Status, DeviceTypes.description and Assets.SerialNumber
What I want as an end result is a form with a drop down box that shows DeviceStatus.Status (which I have working at the moment) with a go button next to it which will call the query that only shows what was selected in that drop down box.
View 5 Replies
View Related
May 12, 2005
I have a query that uses an odbc table.
The query prompt for a date: [Enter Date]
After entering the date, I get error: "ODBC Call Failed"
Yet...when I set the criteria to the date I want: #01/01/2005# I can retrieve the data, no problem.
Any idea why I get the ODBC Call Faile error when prompting for the date?
Thanks....
BJS :confused:
View 1 Replies
View Related
Oct 26, 2004
Hi! I have a query setup that feeds off of three combo boxes on a form. It is setup to allow a user to search and calculate revenue for a selected time period by company, then department, then page. If all three or just company are selected, there are no issues running the data. However, if only company and department is selected I receive an 'ODBC--Call Failed' message. The issues seems to be stemming from the department field as I can link the department table to the main table and the query will run without error. The problem with that bandaid is that the query takes more than 15 minutes to run that way as opposed to about 2 minutes to pull more data at the company level.
Any suggestions on why this is happening or a fix that can be put in place? Any help is greatly appreciated.
I can provide more details if needed. Thanks!
View 6 Replies
View Related
Jul 4, 2013
I am trying to run a query in Access 2010 but I am getting an "Invalid Procedure Call" error. I searched online and found that this error can be caused by broken references.
I opened the VB editor (Alt F11) to search for "Missing" references but I do not see any. These are the 4 that are checked.
1. Visual Basic for Applications
2. Microsoft Access 14.0 Object Library
3. OLE Automation
4. Microsoft Office 14.0 Access database engine Object Library
View 8 Replies
View Related
Aug 7, 2013
When running a query in Access 2013 or 2010 we get an ODBC call failed. However when we run just the form, which the query connects to, it works just fine.
View 3 Replies
View Related
Apr 5, 2013
First query = Sum Products:
Code:
SELECT Sum(Tab1.Inputs) AS SumOfInputs, Sum(Tab1.ValInp) AS SumOfValInp, Sum(Tab1.Outputs) AS SumOfOutputs, Sum(Tab1.ValOut) AS SumOfValOut, Products.Product, Products.VAT, Products.UM
FROM Tab1 INNER JOIN Produse ON Tab1.ProductID = Products.ProductID
GROUP BY Products.Product, Products.VAT, Product.UM, Tab1.ProductID;
Second query :
Code:
SELECT Nz([SumOfInputs],0)-Nz([SumOfOutputs],0) AS Stoc, Nz([SumOfValInp],0)-Nz([SumOfValOut],0) AS ValStoc, IIf([Stoc]=0,0,([ValStoc]/[Stoc])) AS CMP, [Sum Products].Product, [Sum Products].SumOfInputs, [Sum Products].SumOfOutputs, [Sum Products].SumOfValInp, [Sum Products].SumOfValOut, [Sum Products].VAT, [Sum Products].UM
FROM [Sum Products]
GROUP BY [Sum Products].Product, [Sum Products].SumOfInputs, [Sum Products].SumOfOutputs, [Sum Products].SumOfValInp, [Sum Products].SumOfValOut, [Sum Products].VAT, [Sum Products].UM
HAVING (((Nz([SumOfInputs],0)-Nz([SumOfOutputs],0))>0.09 Or (Nz([SumOfInputs],0)-Nz([SumOfOutputs],0))<-0.09));
I need to combine those two query sql code to make only one query.
View 3 Replies
View Related
Sep 30, 2005
I have this code from a Query that works.
SELECT Contacts.*,Contacts.Address1
FROM Contacts
WHERE (((Contacts.Address1) like "*" * (Enter 1st Line of Address here) & "*") AND ((Contacts.Site) = "Miscellaneous"))
ORDER BY Contacts.Site;
I want to replace the data "Miscellaneous" with a Public variable strSite.
If you can help I would be very happy and of course grateful.
Thanks
Ted :confused:
View 7 Replies
View Related
Jan 8, 2008
I have been asked to help with a database that someone is writing.
He has a Table that has 200+ columns and approximately 70 of those columns are Qualifications. The first few columns are Title, Forename, Surname.
What he is trying to do is query the table to find all people with a specific Qualification and that is a Mr.
If I had written the db from the start then I would not have produced so many columns for qualifications. Instead I would have 1 column for quals and the populate each record in this way.
My question to the forum is the following:
With the current structure of his table (200+ Columns) Is there a way that I can produce a Query that will find the results that he requires, 1 specific Qualification and Title, but without displaying all other details in the table?
I understand that I can choose what field to include in the query but what I really do not with to do, is produce 70 different queries in order to filter each qualification.
Any and all help with this question really is appreciated.
Thank you
Bev
View 5 Replies
View Related
Jul 6, 2006
Hi,
1. We have one master table with many records.
2. We'd like to filter out records from the "master" table that match the records on other "exception" tables.
3. As I add records to the "exception" table, I'd like to generate a new table with the records from the master minus the exception table.
I've been reading up and I think that this could be done with queries.
Any suggestions?
Thanks,
Adrian
View 1 Replies
View Related
May 3, 2007
I did some searching and found this function posted by someone in response to the exact same problem I'm now encountering.
But how do I call this in my query?
Function StripZeros(pstr As String) As String
Dim n As Integer
n = 1
Do While Mid(pstr, n, 1) = "0"
n = n + 1
Loop
n = IIf(n > 1, n, 1)
StripZeros = Mid(pstr, n)
End Function
View 2 Replies
View Related
Jul 6, 2005
I am using some code found on this site to creat a log in process. It works great but I want call the UserName and insert it into my database showing
Welcome<Username> you are currently logged in..
Can someone tell me how to call this from a form?
following is the code behind the log in on the "Onload" event.
Thanks in advance.
Fen
Private Sub Form_Load()
On Error GoTo Err_Form_Load
'To ensure a user has logged on correctly we check to see if a userlevel has been set.
'I use the same Select Case below in the "Form_Load" event of each form as some forms you
'may want to set different thins for different user levels rather than setting them
'globally in a module.
With Me
Select Case User.UserLevel
Case 1 'All OK
Case 2 'All OK
Case 3 'All OK
.Command26.Enabled = False
.cmdOpenUsers.Enabled = False
Case 4 'All OK
.cmdOpenUsers.Enabled = False
.AllowAdditions = False
.AllowDeletions = False
.AllowEdits = False
Case Else 'No userlevel set, must have got here via devious means !!
' MsgBox "No User Level Set. ", vbCritical, " LOGON ERROR"
DoCmd.Close acForm, Me.Name
End Select
End With
Exit_Form_Load:
Exit Sub
Err_Form_Load:
MsgBox Err.Description
Resume Exit_Form_Load
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call LogUserOff 'Called from the Unload event incase the user just clicks the main
'Access Window Close Button or exits the Db some other way.
End Sub
View 4 Replies
View Related
Sep 8, 2005
I have a bunch of Forms set up in Access that are updating tables etc......
At present 100% of the code is sitting on the Form. I have some code that is repeated because of a string parsing issue. What I am thinking of doing is writing this code as a couple modules and then call them when needed.
Does that make sense to write them as modules and call them?
How do you call a module???
Thanks
View 4 Replies
View Related
May 31, 2006
Hi
I have three fields on the form. First one is Combo box - "Contact person", Second - "Code" is Text field, Third - "Department" is the text field. Corresponding to this I have a table "Department "with fields Contact person, Code, Department.
I want that when I select the Name from the combo box, corresponding records like Code and Department should appear in the respective text box.
Help me in writing this code.
Thanks in Advance Very much
Deepak
View 1 Replies
View Related
May 31, 2006
Hi
I have three fields on the form. First one is Combo box - "Contact person", Second - "Code" is Text field, Third - "Department" is the text field. Corresponding to this I have a table "Department "with fields Contact person, Code, Department.
I want that when I select the Name from the combo box, corresponding records like Code and Department should appear in the respective text box.
Help me in writing this code.
Thanks in Advance Very much
Deepak
View 1 Replies
View Related
Jul 24, 2005
I am using the two lines of code below Each in separate columns of a query (or two text Boxes on a form) to calculate the elapsed time between two dates formatted as General Dates. The first line of code (in column A, "txtTime1") calculates to the total minutes between the two dates, the second line of code (in column B, "txtTime2") takes the minutes and converts them to total elapsed hours and minutes. They work great, however, I would like to combine this code and place it in only one query column or form Text Box. My VBA is not up to it, can someone out there show me how to combine the code below to produce the hours and minutes in one line of code? Thanks
=DateDiff("n",[StartDate],[CompleteDate])
=[txtTime1]60 & Format([txtTime1] Mod 60,":00") :confused:
View 2 Replies
View Related
May 31, 2006
Hi
I have three fields on the form. First one is Combo box - "Contact person", Second - "Code" is Text field, Third - "Department" is the text field. Corresponding to this I have a table "Department "with fields Contact person, Code, Department.
I want that when I select the Name from the combo box, corresponding records like Code and Department should appear in the respective text box.
Help me in writing this code.
Thanks in Advance Very much
Deepak
View 2 Replies
View Related
Oct 5, 2006
In the code of a button, ive got....
Which should be pulling the value in cb1 in the last cat query, but im getting an error saying it cant find the field "|" refered too...
Basically there is a table called Last Cat, and I want to draw the value of cb1 out of it where the catpathid = 5 so i made the query to do that... but now im abit lost....
Me.combo1.Value = [Last Cat Query1]![cb1]
any help would be awesome.
View 1 Replies
View Related
Nov 23, 2006
Im looking to have a query that selects the "NAME" from a table "tblPeople" where the NAME field begins with "A". Ive tried using WHERE tblPeople.NAME Like "A" with no luck.
Can anyone help me out, im sure im missing something really simple.
View 1 Replies
View Related
Dec 7, 2006
How do you create a query in code. Actually creating a query that appears under the query section of access. Is this possible?
Thank you
View 2 Replies
View Related
Mar 8, 2007
I need to display the results of a query on screen when somebody clicks a button on the form. So I put code in the event of the click that looks like this:
Private Sub Command20_Click()
On Error GoTo Err_Command20_Click
Dim stDocName As String
stDocName = "HHC Report"
DoCmd.OpenQuery stDocName, acPreview
Exit_Command20_Click:
Exit Sub
Err_Command20_Click:
MsgBox Err.Description
Resume Exit_Command20_Click
End Sub
So far, so good, but my problem is that this query is one row with a lot of columns - that creates a lot of pages to look through. Is there a command that would loop it around on the same page, or rotate it clockwise so it's going down the page instead of across?
View 10 Replies
View Related
Jun 12, 2007
I am having trouble with some code I am using on a query. Part of the query comes from two fields in a form. The rest comes from a table. The query then populates a report. The code I have written works fine. The trouble starts when I try and enter in some code so that if some of the fields in the form is left blank, it just returns values based on the fileds that has data, so ignores any blank fields.
I have tried to use examples illustrated in this Forum, but it does not seem to like it. I keep on getting the request to fill in the parameter value. I am sure it is something simple!
This is the code I have entered for the Invoice Date Field:
Between [Forms]![Invoices]![Invoice date 1] And [Forms]![Invoices]![Invoice date 2]
(this is so the user can enter a date range with the two fields)
View 14 Replies
View Related