Senin, 22 Maret 2021

Re: [MSAccessProfessionals] Going through Book.

Correct! I use functions for a variety of purposes. Breaking up a name field, decoding our majors into groups for surveys etc. They are very handy!

Jeff


On Mar 22, 2021, at 9:04 PM, Bill Singer <Bill.Singer@at-group.net> wrote:

OK, that helps.   So in

Function modIF_IF1(Rating As Long) As String

"Rating" is the argument I need to supply and it is defined as Long and the result of the Function  modIF_IF1 will give me a result that will be defined as a String.

 

 

 

 

 

From: MSAccessProfessionals@groups.io <MSAccessProfessionals@groups.io> On Behalf Of jebryme
Sent: Monday, March 22, 2021 2:55 PM
To: MSAccessProfessionals@groups.io
Subject: Re: [MSAccessProfessionals] Going through Book.

 

Hi Bill!

 

The basic difference between a function and a sub is the function returns data. In your example it will return a string. You want to use functions when you plan to use the data without storing it in the underlying data for example you can use a function as a field in a query to manipulate the data. A sub on the other hand returns no data and is often used to edit records or add records in the data.

 

I know  to how enter the argument from the Immediate window.  Next I am going to have to figure out how to pass a variable from a query or another VBA program.

 

Thanks for your help.

Bill

Minnesota

Access 365

 

 

From: MSAccessProfessionals@groups.io <MSAccessProfessionals@groups.io> On Behalf Of Bill Singer
Sent: Monday, March 22, 2021 3:37 PM
To: MSAccessProfessionals@groups.io
Subject: [MSAccessProfessionals] Going through Book.

 

Can someone help me to understand this.

 

I am going through the book Access 2010 VBA programming Inside Out and I come across to ways to do the same thing  (I believe).

 

I am trying to understand the difference between FUNCTIONS  and SUB ROUTINES and whey the first statement is different (and when to use each).

 

Here is the Sub example.

Sub modIF_IF_Simple(Rating As Long)

 

Here is the Function Example

Function modIF_IF1(Rating As Long) As String

 

What is the difference and why is the "As String" needed at the in the function and not the sub.

 

Thanks,

Rookie,

Bill Singer

Minnesota

Access 365

Tidak ada komentar:

Posting Komentar