Modules & VBA :: Code To Return Field Name Rather Than Value

Apr 17, 2014

I have a code that finds the first, second, and third minimum value in a row across the fields. Now, I am trying to find a code to look at these values, find the field it is located, and return the field name. I tried several variations of my code to return the field name rather than the value, but have been unsuccessful to this point.

Function NthMinimum(intPosition As Integer, ParamArray FieldArray() As Variant) As Variant
Dim varTempArray() As Variant, varTempValue As Variant, intArrayValues As Integer
Dim I As Integer, J As Integer
ReDim varTempArray(UBound(FieldArray))
intArrayValues = 0

[Code] ....

As you can see, this works to find these values while ignoring NULLS. How to return the field name?

View Replies


ADVERTISEMENT

Modules & VBA :: SQL Code Return Value And Set To Variable?

Sep 4, 2013

Code:
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Dim SQLstr As String

[Code]....

I created this about 1 hour ago but my laptop crashed and didnt save. So, I open a record set and rs is now loaded with the record I want,

how do I assign the value of "Status" as a vba variable. when I try StatusInt = rs I get the "Type Mismatch" error...

View 4 Replies View Related

Modules & VBA :: Return The Field Name From Expression

Mar 13, 2014

I'm looking for a bit of code for a module that will return the field name from an expression (that uses an array) instead of returning the value in that field.

Example:
(Minimum is a working module that finds the smallest number in the array)
Field1 = 34
Field2 = 53
Field3 = 21
Field4 = 62

GetFieldName(Minimum([Field1],[Field2],[Field3],[Field4])) = "Field3"

I've searched but can't find a way to select the field name anywhere...

View 4 Replies View Related

Modules & VBA :: Use DLookup To Return A Value From Relevant Field

Nov 14, 2014

I have a small table, that only contains one record (and should only ever contain one record, which simply gets edited to suit once in a while).The table is called OtherRates, and the fields are as follows:

WRD_Sat/Sun/BH
WRD_Mon-Fri
AHDifferentia
SKDifferentia
Sat/Sun/BH_OTRate
Mon-Fri_OTRate

I am trying to use DLookup to return a value from the relevant field in this table, however the field to look in is a variable.The code (below) that I have tried returns an error and highlights the DLookup line,.

Code:
Dim WRD
Dim DayType

[code]....

View 3 Replies View Related

Modules & VBA :: Return Multiple Records In A Single Field

Apr 6, 2014

I'm trying to create a report that's based on a query, and the query has three fields: [PersonName], [PersonDate], [PersonShift]. This table holds records for people that worked on certain days and certain shifts. What I want to do is create a report that gives a graphical calendar display of each day in a month, and on any day that the person has a record (and sometimes there are more than one), I'd like to see just the PersonShift records showing in that day's box.

tblPersons
PersonName PersonDate PersonShift
Jason 4/10/14 FIRST
Jason 4/13/14 FIRST
Jason 4/13/14 SECOND

So if I were to print this report for Jason, I'd get all the days in April laid out like a calendar, and on 4/10/14 you'd see "FIRST" in the box, and on 4/13/14. you'd see FIRST and SECOND in the box. All the other boxes would be blank.how to display the calendar, how to display the dates. I'm able to return records to those boxes by creating 31 separate queries, one for each day of the month, and each query returns records for that day. The queries are added to the report as subreports. It all works beautifully.

The thing is, I'm running 31 queries every time I pull the report. Is there a way to code a single field on a report that will run a SELECT statement on the table using variables that are located in fields elsewhere in the record?

If I have a PersonName field on the header of the report, and I have a PersonDate field in the detail of the report's record, can I create a new field in the detail of that record that runs a SELECT statement on qryPersons, and filters the tblPersons by the PersonName on the header of the report and on PersonDate in the record?

I want a field on a report that runs a SELECT statement on tblPersons, I want the field to return only the PersonShift records for that person based upon the PersonDate. Each of the fields on my report have a CalendarDate field, and I want the SELECT statement to return records where the PersonDate matches the CalendarDate, and again, it should only display PersonShift records.

View 2 Replies View Related

Modules & VBA :: Return Rows In Query From Variant Array Return From UDF

Sep 16, 2014

I have a simple UDF that takes a string and returns a variant, which is an array of strings Example Input "Brick Wall" Return value would be a variant array with first element "Brick" and and second element "Wall" Now I have a table with a field of strings, and I want to make a query that returns all the results from the function, one per line.

So if my input table looks like this

[strField]
"kick the ball"
"return the pass"

my query result should looks like this

[Orig] [new]
"kick the ball" "kick"
"kick the ball" "the"
"kick the ball" "ball"
"return the pass" "return"
"return the pass" "the"
"return the pass" "pass"

Last time I had to do something like this I used VBA exclusively, with ADO objects, but I thought a query based solution would be easier.

With my current data the largest return array size my function returns is 27 elements but I wouldn't want to rely on that number being fixed.

View 3 Replies View Related

Modules & VBA :: Code To Check Contents Of A Field In A Table Where Another Field

Sep 11, 2013

I am trying create some code that checks if the contents of the status field in a table is "Authorised" where the ID = something specific for multiple records. If all records witht the specific ID are "Authorised" Then generate a new record in another table. Where to start, perhaps a Dlookup?

View 1 Replies View Related

Modules & VBA :: Return A Value From A Separate Query / Have To Show Up In A Field On Main Form

Jun 28, 2013

I want to return a value from a separate query and have that show up in a field on my main form. The field name from the query is "Six Month Date" and the query name is "DT6Monthqry". I want to return the value displayed in the"Six Month Date" from the query, matching the CustomerID in the query result to the CustomerID that is being displayed on the main form. The CustomerID is a text field.This is the code I placed in the Control Source property for the field I want to be displayed on the main form:

=DLookUp("[Six Month Date]","DT6Monthqry","CustomerID=" & [CustomerID])

The result of this displays a flashing "Error" in the field, even when I go to a Customer that I know has a result in the "DT6Monthqry".

View 8 Replies View Related

Credit Code Get No Return ?

Oct 1, 2006

Can some one help me with this code, I get no return, ???

. Private Sub cust_credit_score_1_AfterUpdate()

If [Forms]![Customer Form]![cust_credit_reply_1] = " [Bad Credit]"Then
[Forms]![Customer Form]![cust_credit_score_1] = 5

ElseIf [Form]![Customer Form]![cust_credit_reply_1] = "[PoorCredit]"Then
[Forms]![Customer Form]![cust_credit_score_1] = 10
Else
[Forms]![Customer Form]![cust_credit_score_1] = 15
End If

End Sub


Thank You For Your Help

Johnny C.

View 14 Replies View Related

Modules & VBA :: Lock Down A Field Through Code?

Jun 7, 2013

I have a field within a form that needs to be modified based off of someone's access level and I have written that part but not sure how to keep others from modifying the field.

Code:
Private Sub Qty_Rcvd_Click()
If ap_GetUserName() = "Danny_Davis" Or ap_GetUserName() = "christopher_ayers" Or ap_GetUserName() = "Tena_McCrackin" Then
GoTo 10
Else
MsgBox "You are not authorized to view this form"
End If
10
End Sub

Right now this code will bring up the msgbox for someone not authorized but once they hit "ok" the msgbox goes away and they can still change the field. What can I type in here to lock down the field for someone not authorized?

View 3 Replies View Related

Modules & VBA :: Code That Populate Field

Feb 25, 2014

I am using MS Access 2010 and I am struggling to write some vba in my database. On my form, I have a Payment Type dropdown field.When someone selects a payment type I want the code to calculate the end date. Then populate the End Date field with the answer.I will be having a few payment types too, but for now on the dropdown I have two.2/Month and 24/Annum.

View 3 Replies View Related

Modules & VBA :: Getting Code For Conditional Default Field Value?

Jan 17, 2014

convert the following into VBA code for an Access 2007 field on a form. It is needed to create a conditional default value based on another field's category: (Note: TransType, MembershipYear and Dues are field names and are all on the form). Based on the TransType (which is really a category of membership) I want the Dues field to have the applicable default value automatically entered.

For MembershipYear > 2008
If TransType="Individual" or TransType="I" Dues=35.00
If TransType="Family" or TransType="F" Dues=50.00
If TransType="Founder" Dues=100.00
If TransType="Student" Dues=10.00
If TransType="Lifetime" Dues="" or is Null
If (TransType is Null or TransType="") and TotalPaid >0, Dues=35.00

View 3 Replies View Related

Modules & VBA :: Check Datatype And Field Size In Code

Feb 6, 2015

I have created code to import and excel file and create a table from that info. Now I need to confirm that the import has the correct Datatype of Number and Fieldsize of Double for one of the columns.

View 2 Replies View Related

Queries :: Return Word Unknown For Any Code That Doesn't Have A Match

Aug 20, 2013

I have lookup table I use to return names for various "Sales Class" codes.It all works good but if there is a code that isn't in the lookup table it leaves that field empty.I want it to return the word "Unknown" for any code that doesn't have a match.Here is the SQL:

Code:

SELECT [Data1].OrderNum, SalesClasses.[Name]
FROM [Data1]
LEFT JOIN SalesClasses ON [Data1].[Sales Class] = SalesClasses.[Code1];

Table examples:

Data1:
OrderNum - Sales Class
111 - class1
222 - class2
333 - classX

[code]...

View 3 Replies View Related

Modules & VBA :: Calculate A Field That Excludes Weekends And Holidays - Code Error

Sep 24, 2014

I am using the function below to calculate a field that excludes weekends and holidays. The weekends are excluded as it is now, but when I try to add in code to exclude holidays I am getting errors. The code for the holidays is in bold and a couple of the errors are Loop without Do so I remove the Loop then I get a Else without If.

Code:
Option Compare Database

Public Function WorkingDays(Due_Date As Date, Result_Date As Date) As Integer
'-- Return the number of WorkingDays between Due_Date and Result_Date
On Error GoTo err_workingDays

[Code] ....

View 6 Replies View Related

Queries :: Form Field Return A Null Then Look At Field In Table

Jun 10, 2013

Trying to run a query using criteria to populate the query by looking at information from a field on a form, if from is closed I need that criteria to look at the table and return all date in table.

View 14 Replies View Related

Modules & VBA :: Return Focus To Access

Sep 4, 2013

I have a database which connects to another application (by creating an object) for the purposes of reading/writing data. Part of the code involves creating an instance of this application, and then taking input from the user via an Access form.However, when I load the form, the focus stays with the other application, and the user has to 'click into' the form in order to reset the focus to the form and key the relevant details. Not the end of the world, granted, but frustrating over time and something I'd like to iron out.

I originally had this process in Excel, and used the following code to change the focus back to Excel (so that the user could key directly into the form)

Code:
Dim ExcCap As String
ExcCap = Application.Caption

' ...assorted code, including creating the object to 'house' the other application...

' Return focus to Excel
AppActivate ExcCap

But this doesn't apply to Access as it utilises the Application.Caption / AppActivate method to identify the appropriate window to switch back to. In Access, I don't have a caption to reference.I've tried setting the focus in the Form_Load event but it doesn't bring the form 'to the fore'

Code:
Private Sub Form_Load()
Me.SetFocus
End Sub

View 8 Replies View Related

Modules & VBA :: How To Cancel Carriage Return And Replace With Tab

Jul 30, 2015

How i can cancel the a carriage return and replace with a tab or stop it moving down my subform and make it move the the next field instead of going to a new line.

I am using the Keydown but don't know how to cancel it, it just bring an message but it stops it moving to a new record,

Code:

Private Sub Barcode_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
MsgBox "rtn pressed"
End If
End Sub
End If

View 5 Replies View Related

Modules & VBA :: Return Name Of A Record Source Table

Feb 19, 2014

I'm new to Access and VB but I managed to write parts of what I want access to do.By tweaking a code I found on the internet, I managed to write a small Subroutine that allows the user to click on one of the fields of a record in a report and then Access opens the form on that specific record.*My code goes something like this:*

Code:

Private Sub Edit_Click()
* Dim strWhere As String
* Dim DocName As String
* DocName = "FormName"
* strWhere = "[Field Name]='" & Field & "'"
* DoCmd.OpenForm DocName, acNormal, , strWhere
End Sub

Now I want to get the name of the Table where the record exists.So, let's say when I click on the "Field" it gets the name of the table where the record with that field exists and sets it in a variable.OR even better would be, get the name of the Form where that record exists but I guess that's a little more complicated since the record is directly linked to the table...*

View 14 Replies View Related

Modules & VBA :: Return Next Primary Key Value Which Is In Specific Format?

Jul 26, 2013

what is the best/cleanest way to return the next primary key value which is in the format yyyy-###.These are case files for the current year, ### being 3 digit number incremented by one for each new case.

I could use a function that finds the last one, checks the date, increments by one and returns it, but maybe I could use a public property or a class? I'm keen to use classes more for code maintenance.With a class then: would i create a PrimaryKey variable of the class type/object, so when I need a new key I would just type PrimaryKey.NewKey, for example?

View 5 Replies View Related

Modules & VBA :: Return Integer Based On Time?

Oct 30, 2013

I have a query with a Start Time where the need to return a set integer in another field in my query. I am attempting to get this to work in my StripSecondsQry.

I am not getting any error messages and I am not getting any output, When I view this in the Locals window I can see that it should be returning 7, but instead I get nothing unless I change it to

Code:
Function SortStart(StartTime As String) As Integer

then I get zero.

I had this working within the query, but I had to add one more time and then received a message that the expression was too complex.

Code:
Sort_Start: IIf([StartTime]="7:00 AM",1,IIf([StartTime]="8:00 AM",2,IIf([StartTime]="8:45 AM",3,IIf([StartTime]="9:00 AM",4,IIf([StartTime]="9:15 AM",5,IIf([StartTime]="10:00 AM",6,IIf([StartTime]="10:15 AM",7,IIf([StartTime]="10:30 AM",8,IIf([StartTime]="12:00 PM",9,IIf([StartTime]="1:30 PM",10,IIf([StartTime]="1:45 PM",11,IIf([StartTime]="2:00 PM",12,IIf([StartTime]="3:00 PM",13,IIf([StartTime]="4:00 PM",14))))))))))))))

View 3 Replies View Related

Modules & VBA :: DLookup Doesn't Return Correct Value

Aug 3, 2015

I'm trying to use a DLookup to get a specific value from a field in a table.

This is what my code currently looks like;

Code:
JOBID = DLookup("[ID]", "MASTER PLANNER", "[JOB NUMBER] = '" & JOB_NUMBER & "'")

Basically I want to get the ID (a number) from a specific record where the JOB NUMBER equals the string I have typed in to a field on the form, also called JOB NUMBER.

However, my problem is that it doesn't navigate to the record where the criteria matches, it just chooses the ID from the very first record of the table.

what I'm doing wrong?

View 9 Replies View Related

Modules & VBA :: Case Differentiation Through Return Value Of A Function

Jan 3, 2014

I would like to select a case depending on the output of a function.

This function tests the syntax of the reporting month.

If the syntax is fine nothing should be done further in the main sub else it should return to the Input window for the reporting month.

Somehow it doesn't work out.

Code:
Public Function RepMonthCheck(rep_date As String) as Boolean
If Len(rep_date) <> 6 Or Left(rep_date, 2) > 12 Or Left(rep_date, 2) < 1 Then
MsgBox ("Reporting rep_date is not in the correct format = mmyyyy")
Return False
ElseIf Right(rep_date, 4) > 9998 Then
MsgBox ("No forecast available for year 9998")

[Code] ....

View 3 Replies View Related

Modules & VBA :: Option Group - IIF Date Return

May 2, 2014

I have a date field in a form fed by an option group. Most of the options return the correct values, but I'm having a hard time with this:

If the inspection date (in another form) is in Jan Feb or March, then return the date 1 Apr of the inspection year. If not, then return 1 Apr of the following year.

Here is the trouble line:

Code:
Case 2
IIf (Month([Forms]![FrmGeneralInspection]![txtInspectionDate]) <= 3), Me![txtReInspectionDate] = DateSerial(Year([Forms]![FrmGeneralInspection]![txtInspectionDate]) + 1, 4, 1), Me![txtReInspectionDate] = DateSerial(Year([Forms]![FrmGeneralInspection]![txtInspectionDate]) + 2, 4, 1)

View 4 Replies View Related

Modules & VBA :: Public Type (variable) For Function To Return More Than One Value

Sep 23, 2014

Question for Documentation purpose: Should the Public Type be declared in its own module?

Or should it be declared in a standard module where non-public functions use it? It is not for a Form module use.

For a Rule Engine, a function is calling one record on 4 different SQL Views (as linked tables) that have the same field format.

For speed, the recordset should only be opened once. However, there are multiple values that must be returned to the result table multiple fields.

One way to return multiple values is an Array. That has over head too.

Another way is to create multiple public variables. Not my choice for documentation. Another is to create a string.

This is a pure code module with several non public functions / subs. What is the documentation preference? List a Public Type close to the function, or place it in the Global module?

Background: A function can only have one return value.

By creating a public Type, multiple values can be returned.

Code:
Public Type Income
Wages As Currency
Dividends As Currency
Other As Currency
Total As Currency
End Type

Use this structure as the return type for a function. In a real situation, the function would look up your database tables to get the values, but the return values would be assigned like this:

Code:
Function GetIncome() As Income
GetIncome.Wages = 950
GetIncome.Dividends = 570
GetIncome.Other = 52
GetIncome.Total = GetIncome.Wages + GetIncome.Dividends + GetIncome.Other
End Function

To use the function, you could type into the Immediate Window:

GetIncome().Wages

(Note: the use of "Public" in the Type declaration gives it sufficient scope.)

Important Notice The way this function is called will work, but is wrong from the aspect it re-calls the recordset over and over.

See the proper way to use it submitted below.

View 5 Replies View Related

Modules & VBA :: DLookup To Return A Value Starting With Specific Letter

Feb 25, 2014

I am trying to use a DLookup to search to find what block goes into the production of an item.

In a table called "dbo_vw_MCE_job_with_materials", each item contains a list of the parts which go into its production in a column titled "Expr1". However there are always more than one parts to this, with varying names.

What I am trying to do is to use a Dlookup to only return the first value which starts with B (as the block number is always the only part on the list which begins with B).

At the moment my DLookup would look ike this:

Code:
MixTypeTxt = DLookup("Expr1", "dbo_vw_MCE_job_with_materials", "[item] ='" & Forms![Theta Input]![ItemNumbertxt] & "'")

However I think as the item column contains the same item number in 8 columns, with different values in the Expr1 column, Dlookup only returns the top value "A-CF0057" (which is irrelevant as far as I am concered) - whereas I am hoping it will be able to pull the "B1499" value from the column as it is the only one starting with a B

Is there anyway to specify which value the dlookup function would return, or is there any way to apply some sort of permanent filter on my table?

View 1 Replies View Related







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