473,394 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Custom function Second()

48
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
Sep 12 '06 #1
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!

;)
Sep 12 '06 #2
sanniep
48
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
Sep 13 '06 #3
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!

:)
Sep 13 '06 #4
sanniep
48
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)
Sep 13 '06 #5
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)
Sep 16 '06 #6
sanniep
48
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!
Sep 18 '06 #7
PEB
1,418 Expert 1GB
Hi,
Create user defined functions in a module like this:

Expand|Select|Wrap|Line Numbers
  1. GLOBAL last_criteria, last_used
  2.  
  3. Function Set_last( Values, criterias)
  4. 'Stop
  5. last_criteria = nts(criterias)
  6. last_used = nts(Values)
  7. Set_last = last_used
  8. End Function
  9.  
  10. Function Show_last( criterias)
  11. Show_last = last_used
  12. End Function
  13.  
  14. Function Show_last_criteria( criterias)
  15. Show_last_criteria=last_criteria
  16. End Function
  17.  
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!

:)
Sep 21 '06 #8
sanniep
48
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
Feb 9 '07 #9
sanniep
48
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
Feb 9 '07 #10
Killer42
8,435 Expert 8TB
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?
Feb 10 '07 #11
sanniep
48
Thanks Killer and PEB for your input!! I've got PEB's functions to work, result works as a charm!

Thanks again! Sander
Feb 14 '07 #12
MrWm
2
Hi,
Create user defined functions in a module like this:

Expand|Select|Wrap|Line Numbers
  1. GLOBAL last_criteria, last_used
  2.  
  3. Function Set_last( Values, criterias)
  4. 'Stop
  5. last_criteria = nts(criterias)
  6. last_used = nts(Values)
  7. Set_last = last_used
  8. End Function
  9.  
  10. Function Show_last( criterias)
  11. Show_last = last_used
  12. End Function
  13.  
  14. Function Show_last_criteria( criterias)
  15. Show_last_criteria=last_criteria
  16. End Function
  17.  
:)
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
May 26 '07 #13
Killer42
8,435 Expert 8TB
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.
May 27 '07 #14
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

Expand|Select|Wrap|Line Numbers
  1. Function nts(Stri) As String
  2.   On Error Resume Next
  3.   Dim result As String
  4.   If IsNull(Stri) Then
  5.     result = ""
  6.   Else
  7.     result = Stri
  8.   End If
  9.   ns = result
  10. End Function
May 28 '07 #15
Killer42
8,435 Expert 8TB
Thanks for that, PEB. So MrWm, does that solve your problem?
May 28 '07 #16
MrWm
2
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?
May 31 '07 #17
Killer42
8,435 Expert 8TB
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.
May 31 '07 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

11
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...
4
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...
1
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. ...
19
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...
8
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...
10
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...
2
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...
1
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...
13
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
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
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.