Passing Each Record To A Function

Aug 1, 2005

I have written a simple module that sorts and compares two strings. Next I am trying to create an event procedure for a button that will send all the values from three selected colums to that function for comparison.


Below is function "Check" from the module

' sImp = importData
' sAns = answerData
' iOpt = option

Function Check(sImp As String, sAns As String, iOpt As Integer) As Integer

Dim lImp As Long 'Imported values (unsorted)
Dim lAns As Long 'Entered values (unsorted)
Dim lAcnt As Long
Dim lCcnt As Long
Dim sAnswer As String 'Correct
Dim iMini As Integer
Dim sImpSort As String
Dim sAnsSort As String


lImp = Len(sImp)
lAns = Len(sAns)

sImpSort = OrderString(sImp)
sAnsSort = OrderString(sAns)

For lAcnt = 1 To lImp
sAnswer = Mid(sImpSort, lAcnt, 1)

' option
Select Case iOpt
' all
Case 1
Check = 1
Exit Function

' or
Case 2
For lCcnt = 1 To lAns
If Mid(sAnsSort, lCcnt, 1) = sAnswer Then
Check = 1
Exit Function
End If
Next

' and
Case 3
If sImpSort = sAnsSort Then
Check = 1
Exit Function
End If
Case Else
End Select

Next

End Function



What would be the best way to send these values to the function? loop through a recordset?
(Note: Not sure how many records the DB will eventually store. Lets just say 10,000 for now)

Any suggestions would be greatly appreciated..

Thanks

salmonman

View Replies


ADVERTISEMENT

Subforms - Passing Name To A Function

Feb 24, 2005

Hey long time browser, first time poster!

HELP!!!

Ok, here is the problem that I can't seem to find any posts on here talking about. I have a form, let's call it FormA and a subform (subformA). I am using a non-activeX calendar control, which I did not write. I was informed it could be used on subforms but its not working. In reviewing the code it is looking for the activeform name to be passed to it. This works when the calendar function is called in the FormA, but when it is called in SubformA, it can identify the field that I want the date selected to be entered into, but it does not recognize the subform as being the active form.

The code it's using to determine activeform name is:
Screen.activeform.name

From my research I have found that when the subform has the focus, the activeform.name returns the name of the parent form.

The question: How can I determine the subform name and pass it as a variable to the calendar program?

Mark

View 1 Replies View Related

Passing Operator Into Query Via Function

Jan 16, 2006

I have built a function which passes values into the criteria of a saved query. It has worked very well until I recently built a query builder based on this same concept. The user can select from a list of operators "<=", ">=", ">", "<", "=".

Example, the function will pass into the criteria the following:
<150

Unfortunately, I have exhausted all avenues for passing the "<" less than or greater than signs into the criteria. The Access SQL forces an equals sign before the passed in criteria and thus treats the "<150" as the entire criteria.

I have overcome no criteria by defaulting the function value to pass in the wildcard "*" and putting "Like" in the criteria.

Has anyone every handled a "variable" operator in a saved query in Access? :confused:

I am aware that I can change the QueryDef, use temp tables, and do several other longer methods, but the success of this concept will reduce an large amount of coding effort as well as make the software much easier to transfer knowledge on.

This overall method is really a great way to reuse criteria based on a form without hard coding.

Thank you in advance for your help,

Dave

View 3 Replies View Related

Modules & VBA :: Calling A Function And Passing Variables

May 29, 2015

I have never tried passing variables while calling a function so I don't know what the heck I'm doing. I'll give a simplified example of what I'm trying to do. The second variable vRank is reporting properly but the first one vID gets "stuck" on whatever the first item in the listbox is.

Code:
Dim vrt As Variant
Dim upSQL As String
For vrt = 0 To Me.List1.ListCount - 1
If Me.List1.Selected(vrt) = True Then
Call ChangeUp(Me.List1.Column(0, vrt), Me.List1.Column(1, vrt))

[Code] ....

View 3 Replies View Related

Forms :: Passing Text Box Data To A Function Via A Query

Jan 28, 2014

I have a function in a module that looks like this (it takes 2 dates as arguments):

Code:
Function get_KPIScanAgeRange(in_ScanDate As Date, KPIDate As Date) As String
Dim ret As String
ret = "Invalid"
' return value, by default is because age is negative number

[Code] .....

I'm trying to pass the date in a text box which exists in a form called "d3FormAging". The text box name is "KPIDate". The query looks like this:

Code:
SELECT Query_d3_Open.[Company No], get_KPIScanAgeRange([Scan date],[Forms]![d3FormAging]![KPIDate]) AS KPIScanAgeRange, Count(Query_d3_Open.[Scan date]) AS Scans
FROM Query_d3_Open
GROUP BY Query_d3_Open.[Company No], get_KPIScanAgeRange([Scan date],[Forms]![d3FormAging]![KPIDate])
ORDER BY Query_d3_Open.[Company No], get_KPIScanAgeRange([Scan date],[Forms]![d3FormAging]![KPIDate]);

For some reason Access doesn't recognize the "[Forms]![d3FormAging]![KPIDate]" when I pass it to the function. I get run-time error 3070 with information that Access can't recognize this expression even though the code should be correct as it's made with the expression builder and I'm sure the form that contains the text box is open when the query runs.

View 2 Replies View Related

Reports :: Passing Variable To Report Record Source?

May 7, 2013

I have a subroutine that successfully builds a SQL statement "strSQL", which is a public variable.

Using msgbox, I can read that the value is correct -
SELECT * from tblIncidents WHERE [Nature] = 'Hover';

(The select statement may be complex, e.g. [Nature] = 'hover' AND [COLOUR]= 'Blue' AND [GRADE] = 'High')

I want to pass the variable strSql to my report rptIncident in the following command:

Private Sub CmdPrintReport_Click()
If Right(strsql, 1) <> "'" Then 'check if statement was built
Else
strsql = strsql & ";" 'add trailing ; to statement
MsgBox strsql
DoCmd.OpenReport "tblincidents", acViewNormal, , strsql
End If
End Sub

I get a flashing error, then runtime error 3075 - |1 in query expression '|2'.

View 6 Replies View Related

Forms :: Passing Field Value From One To Another Form That Creates A New Record

Mar 13, 2013

I have several different sub-forms that have a button that opens a new form which creates a new record. Each of the different sub-forms have a field value that needs to be passed to the new record when the other form is opened. I've tried a few solutions, but to no avail. Right now I'm using the macro functionality as follows for one of the subforms:

ACTION ARGUMENTS
--------------------------------
RunCommand SaveRecord
OpenForm frmDocumentNew, Form, , [AssociatedClientTracking]=[Forms]![sfrm_ClientTracking]![ID-ClientTracking], , Normal
OnError Next,
GoToRecord ,,New,
MsgBox =[MacroError].[Description], Yes, None,
SetProperty [AssociatedClientTracking], Enabled, Me.ID-ClientTracking

The problem I think is that I'm creating a new record so the value doesn't get passed. The new record is only created after the user begins to enter data in the new form that was opened.

View 2 Replies View Related

Forms :: Creating A New Record From Another Form And Passing Values?

May 20, 2014

Have a form that contains fields AssociatedProject, AssociatedRelease and then the user hits a button to create a new record and a new form opens to display this newly created record which sets the fields and also sets a field called Type. There is no issue with setting the field values and the new record is created. However, when the form opens to display the record it displays another record instead (usually the one before it). I think it could be related to the fact that the db resides on a shared drive which periodically has slow connectivity. However, I'm looking for a solution, perhaps modifying the code?

Here's the code:

Private Sub Command17_Click()
Dim strSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim ctl As Control
Dim varItem As Variant
On Error GoTo Err_Command17_Click
Set db = CurrentDb()
Set rs = db.OpenRecordset("Tbl_Main", dbOpenDynaset, dbAppendOnly)

[code]....

View 6 Replies View Related

Reports :: Calling A Report From A Form - Record ID Not Passing

Jun 24, 2014

I am using an on-click event on my form to call up a report for the current record. It has been a while since I've used the form to call the report, but I always remember it working correctly. Today when I try to call up the report, it opens but no record is being pulled up so the report pulls up blank.

Code:
DoCmd.OpenReport "rptSupplierInformation", acViewPreview, , "[OperationID]=" & [cboMoveTo], acWindowNormal

View 1 Replies View Related

Forms :: Passing Values From One Form To A New Record In Another Form

Oct 25, 2013

Have one form that contains values AssociatedProject and AssociatedRelease that need to be passed onto another form that opens with a new record. Have tried different variations based on what I read here and couldn't get them to work.

Initial form - frm_ViewList contains the values that I need to pass on and has a "Add" button to bring up the new form that also creates a new record. The add button contains the following:

Dim stDocName As String
MyAssociatedProject = Me.AssociatedProject
MyAssociatedRelease = Me.AssociatedRelease
stDocName = "Frm:ManageQuestionsAnswersProc"
DoCmd.OpenForm stDocName, acNormal
DoCmd.GoToRecord , , acNewRec

Then in the second form Frm:ManageQuestionsAnswersProc the following code is contained in the Before Insert:

Me.AssociatedProject = MyAssociatedProject
Me.AssociatedRelease = MyAssociatedRelease

View 3 Replies View Related

First Record Function

Jul 3, 2007

Hello,
I thought this would be easier, but the results I'm getting are inaccurate.

I have a table that includes items and dates. There are multiple records per item. I want to show each item only once with the earliest corresponding date. I've sorted, used the TOP, DISTINCT, and FIRST functions and can not seem to come up with the right combination.

The query is already works from another query that sorts by item and date. I just need to pull the first record for each. I would appreciate any suggestions!

View 3 Replies View Related

Perform Function Before Next Record

Feb 27, 2006

Hi,

Is there a way i can perfrom some functions before or after the next record in the recordset is loaded. (form is set to continuous)

For instance:
If i have 5 records in my forms record source after the 1st it will msgbox "sumin" after the second msgbox "sumin" and so on?

This is the record source in the properties of the form by the way not a recordset within vba?

Thanks
k0r54

View 2 Replies View Related

Sum Function Only Adding First Record Of Each Group

Mar 8, 2008

Hi Guys, sorry to bother you but I'm really stumped. I've looked through some similar sounding old posts on here but they don't seem to answer my problem...

I've got a report, which is grouped, in the footer of each group a SUM label should add the contents of the pricce column, however strangely it only adds the first record of each group as a running total. I've tried both the "Over all" and "Over group" attributes of the running sum property, but they make no difference.

Any help would really save my day. Cheers!

View 11 Replies View Related

Running A Function When Moving To Next Record

Mar 13, 2006

Hi,

How can i run some vba cose directly after i click the move next button on the navigation but at the bottom of the form.

Thanks
k0r54

View 2 Replies View Related

Modules & VBA :: Report Function To Trigger On Next Record

Jun 25, 2014

im working on an access report and would like a little vba script to run on when the page prints out the next record (mostly just need to hide/unhide a few objects and change the value of a variable on the report when it prints the next record)how i can trigger this (as there seems to be no onNextRecord event handler)

edit: upon a better inspection of the reports record source i realized that on next record doesnt actually work (i could force it to by adding a few new fields to queries and forcing endless loops), what i needs actually a lil more complicated

my report has a header, in the header is a field called productionNo, the record source has multiple instances of prodno's with countless duplicates, what i need is a function to trigger when the productionno changes, there will probably be a few pages with the same production number (theyd be grouped together though), so it should only trigger when the value changes, not when it stays the same

View 3 Replies View Related

Can't Modify/add Records Because Of Record Source With COUNT Function!!!!

Jun 19, 2006

I modified a form and now it seems it's impossible to modify/add records. It seems that all comes from when I modified my record source query to add a a field in which it COUNTs all related records in another table. Now the form can't modify anything else but I need to change other fields or add new records!
In other words: how can I add a simple box which, for every record of my table/form, counts the number of related records in another table (relationship is 1-to-many, and of course is based on a field in table2) letting me modify and add records?
Thank you

View 13 Replies View Related

Using Countif Function For Multiple Fields From Specific Record

May 28, 2015

Using Access 2010

I'm an expert user in Excel and am trying to learn more about Access, so I relate many of the functions to what they are called in Excel. And what I'm trying to do right now is count the number of fields in a specific record where the value is a specific result (CountIf).

For example, I need to return the number of fields in a specific record where the value is "Meets Requirements". The specific record will be determined by the Name, Contact, and Email fields (which together comprise the Primary Key).

Is there a way to count the values in multiple fields that equal "Meets Requirements"?

View 7 Replies View Related

Forms :: Unable To Get Preview Selected Record Function To Pull UniqueID Field

Aug 22, 2014

I am attaching a picture of what I am talking about as this is going to get confusing...at least it is for me.

I have a Navigation Form that holds 7 tabs that pull reports or data entry forms.

I am trying to get the Preview Selected Record function to pull the UniqueID field from the Data Entry Form and generate a report for printing.

I can search by UniqueID in the data entry form with no problem, it is linked to two subforms with no problem.

Here is the code I have used most successfully:

Code:
DoCmd.OpenReport "rpt1", acViewPreview,, "UniqueID =" & Forms!MainForm!NavigationSubform.Form.UniqueID

This actually works, but every time the print preview is closed, it crashes Access. I have researched this particular issue, and some of the solutions I have read and tried lead to "that method is not allowed or supported" errors or Run-Time 438 errors.

View 9 Replies View Related

Tables :: Find Record Button Added To A Form To Adjust Search Function

Apr 6, 2015

Is it possible on the Find Record button added to a form to adjust the search function so it defaults to a specific box on the form? I have a form for tracking employee's and on my Find Record button I would like it to default to the Last name instead of the Record number.

View 3 Replies View Related

Modules & VBA :: Creating A Function That Counts Records And Use That Function In A Query

Dec 11, 2013

So basically I need making a function that will count the number of records from another table/query based on a field from the current query.

View 2 Replies View Related

Forms :: SUM Function Produces Error From Calculated Function

Jan 30, 2014

I have a project at hand and it's been a predecessor of mine and client has asked me to do some work on it and extend functionality - but I have not really delved into Access before and I have had to worked my way through to this final snag :/

The Main Form has one sub form. This sub form allows the user to add multiple order items i.e. qty, stock, description from records within the system - fairly straight forward.At the last column of each row is the sub total of those particular items i.e.

Qty Unit | Item ID | Total
-----------------------
2 | 1234 | 80.00
------------------------
1 | 43526 | 20.00
------------------------
> | |

So the total is a function of =[Qty Unit] * [Unit Price].Then in the Footer of this SubForm is the Sub Total

=SUM([Qty Unit] * [Unit Price])

All fine and well..... However, the additional functionality kicks in.

Lets add the additional customer_id from the Main Form. Each Item bought is dependent on the customer_id i.e. they get special prices depending on who they are.So a New table is made which has the Item ID and SpecialPriceID (of a table to define as a specialPrice) and the Price linked to this Item and Special Price category. So say that there are two groups of users "wholesale" and "nonwholesale" these would be SP_1 and SP_2 and each client is defined either one of these, and each stock item has a Price for each SP_1 and SP_2. Hopefully I've explained myself there.

Back to the SubForm. So now the Total needs to calculated differently with needed the external customer_id from the Main Form.

Code:

Function CalculateSpecialPrice(ItemID As String, CustomerID As String, Unit As Integer)
Dim SPSelect As String
SPSelect = "SELECT Price FROM [Items_SpecialPrices] WHERE"
SPSelect = SPSelect & " ItemID = '" & ItemID
SPSelect = SPSelect & "' AND SpecialPriceID = (SELECT SpecialPriceID FROM Customers WHERE customer_id = " & CustomerID & ") "

[code]....

its the sub total I just keep on getting #Error on. I have even watched (using alerts) that the correct return variable is the same as the individual rows. This is the equation I used for the SubTotal within the footer.

=SUM(CalculateSpecialPrice([Item ID], [Form]![FormName]![CustomerID], [Qty Unit]))
#Error

View 2 Replies View Related

Date Function/need Time Function

Jun 9, 2005

We have a date function that converts a text date format. Can someone help me with time function to do the same thing? We want military time. The field is like this now: txt fields.
160037
213137
224356
235716
235800
12341
21708
22732
Here is the date function we use:
Function f2Date(strDateOld As String)
Dim strDate As String, strMonth As String, strYear As String
strMonth = Mid(strDateOld, 5, 2)
strDate = Right(strDateOld, 2)
strYear = Left(strDateOld, 4)
f2Date = strMonth & "-" & strDate & "-" & strYear
f2Date = CDate(f2Date)
f2Date = Format(f2Date, "mmmm d yyyy")
End Function

View 9 Replies View Related

Now Function To Convert To Date Function

May 25, 2006

Hi all,

I need a little help. In my DB, I have a command button set up (I was tired of typing in dates) for date, but I used the Now function, which also gives me the time.

Now I have over 3000 subrecords of the main ones. I now need to queries transaction for that specific date, but it also retrieves the time.

I tried to go back and change the NOW to DATE in VB, but the code does not run.

How do I change all records that have date and time (using NOW function) and only click that command button to show only the date (mm/dd/yyyy)?

Thanks in advance.

View 1 Replies View Related

Argument Passing

Sep 18, 2006

I have a statemtn like this

DoCmd.OpenQuery("UPD_RECEIPT_IMP")

When I run the above, it pops up the input box for user to key in the argument.

How can I stop this and pass the argument to the query in macro

Need help on this.Thanks...

View 1 Replies View Related

Passing Value To A Sub Form

Feb 26, 2005

Hello,

I have a combo box on a main form and one on a subForm (DataSheet View)...

I want the value in the main_combo to populate the sub_combo for every record in the subform.

I think the code would look like this, but I cant get it to work?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub MAIN_DUNS_AfterUpdate(Cancel As Integer)

Me.CLIENT_DEAL.SUB_DUNS = Me.MAIN_DUNS.Value

End Sub

MAIN_DUNS= Combo on main form
SUB_DUNS= Combo on sub form
CLIENT_DEAL= Sub Form
DEAL_INFORMATION=Main Form
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Any Ideas on how to get this to work correctly??

View 1 Replies View Related

Passing Criteria

Nov 16, 2004

I am using Office/Access 2003. I have created a report that functions fine within access. The report is based on a query requesting the users Representative ID. It functions as expected. We then creayed a web page using the same query. Again this works quite well. The user clicks on the link - Access pops up the criteria dialog asking for the rep id. What our problem is that we are trying to determine where we can put the Rep ID in the page so it will automatically fill in the Criteria Dialog. We see no place in the access page where the criteria can passed. We have the criteria because they use it when they sign in to the sight. I can pass it as a hidden field, an application variable, or even a server variable but how do I get the web page to see it and stuff it into the criteria dialog.

Frustrated in Tucson! Thanks for your help in advance

Greggers

View 2 Replies View Related







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