Hello Experts,
I would like to make a custom function Second() for Access in VB. This function should return the second value from a field like the function First gives the first value.
This function should be like the integrated function First() and Last() in Access.
For an expert like you this shouldn't be to hard I hope.. Can anyone help me out with the code for this function?
Thanks for your time! Sander
17 3180 PEB 1,418
Expert 1GB
Dear,
I think that in Access there is a function like this!
Second(MyTime)
Take care my friend!
;)
Dear,
I think that in Access there is a function like this!
Second(MyTime)
Take care my friend!
;)
Ha, thanks PEB! But I want to use the function in a query-expression for a non-time field. Based on the code for the First function I would like to create Second, Third, Fourth, etc functions..
Could you help me out? Thanks again, Sander
PEB 1,418
Expert 1GB
In fact in the queries First(Expression) or Last(Expression), also Sum and Count() aren't function in Basic and aren't build in also!
They are part of the SQL standard used by MS Access
I don't know how to add reserved words and commands in MS Access SQL language!
Reelly a VB function can help you, but first you should determine your parameters!
Function in VB like you want:
Dcount("Field", "Table","Criteria")
So supply us parameters for your function!
:)
In fact in the queries First(Expression) or Last(Expression), also Sum and Count() aren't function in Basic and aren't build in also!
They are part of the SQL standard used by MS Access
I don't know how to add reserved words and commands in MS Access SQL language!
Reelly a VB function can help you, but first you should determine your parameters!
Function in VB like you want:
Dcount("Field", "Table","Criteria")
So supply us parameters for your function!
:)
Thanks again PEB. I want to use this for my rows to columns problem, I'm not getting your solution in the other thread to work..
Idea:
Terminalno Item Serialno
123456 Housing 256-5899-6
123456 Print P132589
123456 Display 120-A458
What I want
Terminal 123456 contains Housing, Print, Display
Something like: IF Terminalno=Terminalno then Terminalno, First(item), Second(Item), Third(Item)
PEB 1,418
Expert 1GB
Hey Man
Semply you need a function that enumerates the values like this:
Terminalno Item Serialno Number_Entry
123456 Housing 256-5899-6 1
123456 Print P132589 2
123456 Display 120-A458 3
When you have this vision it's easy to do an crosstab using as coulmn header the number_entry isn't it?
Have a nice day!
:)
Thanks again PEB. I want to use this for my rows to columns problem, I'm not getting your solution in the other thread to work..
Idea:
Terminalno Item Serialno
123456 Housing 256-5899-6
123456 Print P132589
123456 Display 120-A458
What I want
Terminal 123456 contains Housing, Print, Display
Something like: IF Terminalno=Terminalno then Terminalno, First(item), Second(Item), Third(Item)
Hey Man
Semply you need a function that enumerates the values like this:
Terminalno Item Serialno Number_Entry
123456 Housing 256-5899-6 1
123456 Print P132589 2
123456 Display 120-A458 3
When you have this vision it's easy to do an crosstab using as coulmn header the number_entry isn't it?
Have a nice day!
:)
That's what I want Peb! But when the TerminalNo changes the count has to start over.
Like this:
Terminalno Item Serialno Number_Entry
123456 Housing 256-5899-6 1
123456 Print P132589 2
123456 Display 120-A458 3
145898 Screen 589965 1
145898 Print P158899 2
What does this function look like?
Thanks again mate!
PEB 1,418
Expert 1GB
Hi,
Create user defined functions in a module like this: -
GLOBAL last_criteria, last_used
-
-
Function Set_last( Values, criterias)
-
'Stop
-
last_criteria = nts(criterias)
-
last_used = nts(Values)
-
Set_last = last_used
-
End Function
-
-
Function Show_last( criterias)
-
Show_last = last_used
-
End Function
-
-
Function Show_last_criteria( criterias)
-
Show_last_criteria=last_criteria
-
End Function
-
In your query in the Field row:
Ranking:IIF(Show_last_criteria([Your_Field])=[Your Field with Criteria],Set_last(nz(Show_last([Your Field with Criteria]))+1, [Your Field with Criteria]),Set_last(1, [Your Field with Criteria]))
Be careful you need to append the results in a table before use the result in a crosstab!
An other solution for this field you can find about a post for the ranking in MS Access Forum! There was a very usefull link!
:)
Hi Peb,
Priorities shifted so I didn't look into this problem since now.. Thanks for you september reply!!
I will try your function, thanks for the effort!
Sander
Man, I don't get this to work!! Whaooaoaoaoao!!
Peb, can I sent you a sample database? It will contain 2 tables, a sample table and a table how I want it to be. Could you applicate your solution to this database?
Hope to hear from you mate! Grtz, Sander
Can't you do a fairly simple VBA function which would open a dataset with the specified criteria, then do MoveFirst, then MoveNext, and return what it finds?
Thanks Killer and PEB for your input!! I've got PEB's functions to work, result works as a charm!
Thanks again! Sander
Hi,
Create user defined functions in a module like this: -
GLOBAL last_criteria, last_used
-
-
Function Set_last( Values, criterias)
-
'Stop
-
last_criteria = nts(criterias)
-
last_used = nts(Values)
-
Set_last = last_used
-
End Function
-
-
Function Show_last( criterias)
-
Show_last = last_used
-
End Function
-
-
Function Show_last_criteria( criterias)
-
Show_last_criteria=last_criteria
-
End Function
-
:)
I have copied these functions into a module but I get an error that the nts(criterias) function is not defined.
Did I miss something?
Thanks...Wm
I have copied these functions into a module but I get an error that the nts(criterias) function is not defined.
Did I miss something?
I vaguely recall a similar issue coming up some months back. I think nts() might have just been some function that PEB created to avoid returning a null value, or some such thing.
Until we sort out exactly what the story is, you might try simply not using the function, and see what happens. If the intention is simply to store and retrieve a value, then transferring directly to/from the global variable might be good enough.
I've sent a message to PEB, asking him to look in on this thread - hopefully he can shed some light.
PEB 1,418
Expert 1GB
I vaguely recall a similar issue coming up some months back. I think nts() might have just been some function that PEB created to avoid returning a null value, or some such thing.
Until we sort out exactly what the story is, you might try simply not using the function, and see what happens. If the intention is simply to store and retrieve a value, then transferring directly to/from the global variable might be good enough.
I've sent a message to PEB, asking him to look in on this thread - hopefully he can shed some light.
Yeah Killer its just like this - Function nts(Stri) As String
-
On Error Resume Next
-
Dim result As String
-
If IsNull(Stri) Then
-
result = ""
-
Else
-
result = Stri
-
End If
-
ns = result
-
End Function
Thanks for that, PEB. So MrWm, does that solve your problem?
Well, it does remove the code error I was having, however the query that I am using (based on PEB's Sept 21st post) displays an error in the ranking field of every record:
Query -
Ranking:IIF(Show_last_criteria([Your_Field])=[Your Field with Criteria],Set_last(nz(Show_last([Your Field with Criteria]))+1, [Your Field with Criteria]),Set_last(1, [Your Field with Criteria]))
My query looks at EmpID, Date, Score, and the Ranking. I am trying to rank the scores for each user for each month, to create the crosstab query. I have used EmpID to replace [Your_field] and [Your Field with Criteria].
I can't seem to find my error...any suggestions?
Also, in the query above there is a function nz() that I don't know what it does. Is this the problem?
Hm... I suppose the nz() function might be the problem. But it's a function built into MS Access, so as far as I know it should be alright.
One thing I would suggest is to use MS Access directly to test your query. It's much quicker and easier to play with the query in Access's GUI query designer. Once you've got it working, then you just go to the SQL view and copy it. (Note, you can also paste you SQL into there in the first place.)
Quoted from online help in Access... Nz Function
You can use the Nz function to return zero, a zero-length string (" "), or another specified value when a Variant is Null. For example, you can use this function to convert a Null value to another value and prevent it from propagating through an expression. Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kelvin Jones |
last post by:
Hey, I am trying to write a custom assert function that would be used
to forward a user to an error page if the assertion fails. Here is the
definition of this function and an example of its...
|
by: Rudy |
last post by:
Hello all,
I'm sure there is, just can't figure it out. I have the RGB code and the
color number. But the color doesn't exsist in Visual studio.net. Can I add
this color to the system pallet it...
|
by: CapeCoder |
last post by:
I'd like to use the Excel.WorksheetFunction library to compute median
and percentiles in a user-defined function. I'd like to use the data
from the calling report as the function argument.
...
|
by: Deniz Bahar |
last post by:
Hi,
I would like to call one of my functions the exact name as an existing
C library function (for example K&R2 exercises asks me to make an atof
function). If I don't include the header with...
|
by: Tinus |
last post by:
Hello all,
I've create a custom control (UserControl) and have a custom Item
Collection. The control is a custom calendar which is draw using the
Graphics Rectangle etc. functions. It is drawn...
|
by: Rigs |
last post by:
Hi,
I have a textbox with a Custom Validator that utilizes the OnServerValidate
method for that textbox. This works fine, however the method only executes
when data exists in that textbox after...
|
by: Alani |
last post by:
Hello All,
I'm a new ASP.NET programmer and I want to create a custom control
consist of two properties (Number1) and (Number2) and both of them are
integers and default value = 0,
now I'm...
|
by: rn5a |
last post by:
I have created a custom control button which when clicked displays a
message in the JavaScript alert dialog. I could successfully compile
the VB class file into a DLL & also could add it to the...
|
by: Matt F |
last post by:
I have a deployment project that I'm setting up. I need to perform a
different custom action based on whether this is a first time install or an
update. Does anyone have any idea if it's possible...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |