473,385 Members | 1,588 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,385 software developers and data experts.

Is there something like a pointer variable of C in Access?

I dont know whether this is a stupid question. But does access have
something akin to the pointer variable in C - or for that matter the
'&' operator in xbase.

I will explain my reason for wanting it too. I often use SQLs in which
the where condition gets the data from a variable. e.g

SELECT * from Customer
WHERE CustID = strID

strID being a public variable. But of course the above SQL does not
work as such, because SQL can't read that variable. So I use a
function like

Public Function GetID()
GetID=strID
End Function

and the actual SQL I use is

SELECT * from Customer
WHERE CustID = GetID()

The problem is, each time I have to write a function. Whereas in xBase
for example I would have a single function like this

Function GetVar
Parameters InVar
GetVar = &InVAr
Return GetVar

so that if I call the function as GetVar(strID) I would get the strID
value.

Any help would be appreciated
Sunil Korah
Nov 13 '05 #1
3 1420
Hmm, ok, it's not exactly clear what you are doing.

If you are building SQL statements on the fly then you can just concatenate
the variable value into the statement.

e.g.
dim strSQL as string

strSQL = "SELECT * from Customer " _
& "WHERE CustID = " & strID

If you're using a query and your using it to open a recordset then you can
use parameters and fill the parameters.

In DAO it would go like this

dim loDB as DAO.Database
Dim loQdf as DAO.Querydef
Dim loRst as DAO.Recordset

set loDb = Currentdb
Set loQdf = loDb.QueryDefs("YourQuery")
With loQdf
.Parameters(0) = strID
set loRst = .OpenRecordset
End with

In ADO
Dim loDB As ADODB.Connection
Dim loQdf As ADODB.Command
Dim loRst As ADODB.Recordset
Dim strID As String

strID = 1
Set loDB = Application.CurrentProject.Connection
Set loQdf = New ADODB.Command
With loQdf
Set .ActiveConnection = loDB
.CommandText = "YourQuery"
.CommandType = adCmdStoredProc
Set loRst = .Execute(Parameters:=Array("1"))
End With

If your using the query's as recordsources or rowsources then you could just
create a generic function to return generic variables

Sou you could just have a function
Function QueryParam(Index as long) as Variant
Select Case Index
Case 0
QueryParam = strID
Case 1
QueryParam = lngID
Case 2
QueryParam = dblAnotherVar
' ...
End Select
End function

Or you could programatically change the SQL of the query.
--
Terry Kreft
MVP Microsoft Access
"Sunil Korah" <hb*****@indiatimes.com> wrote in message
news:72**************************@posting.google.c om...
I dont know whether this is a stupid question. But does access have
something akin to the pointer variable in C - or for that matter the
'&' operator in xbase.

I will explain my reason for wanting it too. I often use SQLs in which
the where condition gets the data from a variable. e.g

SELECT * from Customer
WHERE CustID = strID

strID being a public variable. But of course the above SQL does not
work as such, because SQL can't read that variable. So I use a
function like

Public Function GetID()
GetID=strID
End Function

and the actual SQL I use is

SELECT * from Customer
WHERE CustID = GetID()

The problem is, each time I have to write a function. Whereas in xBase
for example I would have a single function like this

Function GetVar
Parameters InVar
GetVar = &InVAr
Return GetVar

so that if I call the function as GetVar(strID) I would get the strID
value.

Any help would be appreciated
Sunil Korah

Nov 13 '05 #2
Whoops,
Set loRst = .Execute(Parameters:=Array("1"))

should be
Set loRst = .Execute(Parameters:=Array(strID))

--
Terry Kreft
MVP Microsoft Access
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:Hz********************@karoo.co.uk...
Hmm, ok, it's not exactly clear what you are doing.

If you are building SQL statements on the fly then you can just concatenate the variable value into the statement.

e.g.
dim strSQL as string

strSQL = "SELECT * from Customer " _
& "WHERE CustID = " & strID

If you're using a query and your using it to open a recordset then you can
use parameters and fill the parameters.

In DAO it would go like this

dim loDB as DAO.Database
Dim loQdf as DAO.Querydef
Dim loRst as DAO.Recordset

set loDb = Currentdb
Set loQdf = loDb.QueryDefs("YourQuery")
With loQdf
.Parameters(0) = strID
set loRst = .OpenRecordset
End with

In ADO
Dim loDB As ADODB.Connection
Dim loQdf As ADODB.Command
Dim loRst As ADODB.Recordset
Dim strID As String

strID = 1
Set loDB = Application.CurrentProject.Connection
Set loQdf = New ADODB.Command
With loQdf
Set .ActiveConnection = loDB
.CommandText = "YourQuery"
.CommandType = adCmdStoredProc
Set loRst = .Execute(Parameters:=Array("1"))
End With

If your using the query's as recordsources or rowsources then you could just create a generic function to return generic variables

Sou you could just have a function
Function QueryParam(Index as long) as Variant
Select Case Index
Case 0
QueryParam = strID
Case 1
QueryParam = lngID
Case 2
QueryParam = dblAnotherVar
' ...
End Select
End function

Or you could programatically change the SQL of the query.
--
Terry Kreft
MVP Microsoft Access
"Sunil Korah" <hb*****@indiatimes.com> wrote in message
news:72**************************@posting.google.c om...
I dont know whether this is a stupid question. But does access have
something akin to the pointer variable in C - or for that matter the
'&' operator in xbase.

I will explain my reason for wanting it too. I often use SQLs in which
the where condition gets the data from a variable. e.g

SELECT * from Customer
WHERE CustID = strID

strID being a public variable. But of course the above SQL does not
work as such, because SQL can't read that variable. So I use a
function like

Public Function GetID()
GetID=strID
End Function

and the actual SQL I use is

SELECT * from Customer
WHERE CustID = GetID()

The problem is, each time I have to write a function. Whereas in xBase
for example I would have a single function like this

Function GetVar
Parameters InVar
GetVar = &InVAr
Return GetVar

so that if I call the function as GetVar(strID) I would get the strID
value.

Any help would be appreciated
Sunil Korah


Nov 13 '05 #3
Terry,

Thanks for such a detailed reply. I've been using the concatenation
approach mostly, but it becomes a pain whenever some fields are added
etc- you have to redo the whole concantenation stuff. So I started
using queries and I think the parameter method will work for me.

Sunil Korah

"Terry Kreft" <te*********@mps.co.uk> wrote in message news:<G6********************@karoo.co.uk>...
Whoops,
Set loRst = .Execute(Parameters:=Array("1"))

should be
Set loRst = .Execute(Parameters:=Array(strID))

--
Terry Kreft
MVP Microsoft Access
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:Hz********************@karoo.co.uk...
Hmm, ok, it's not exactly clear what you are doing.

If you are building SQL statements on the fly then you can just

concatenate
the variable value into the statement.

e.g.
dim strSQL as string

strSQL = "SELECT * from Customer " _
& "WHERE CustID = " & strID

If you're using a query and your using it to open a recordset then you can
use parameters and fill the parameters.

In DAO it would go like this

dim loDB as DAO.Database
Dim loQdf as DAO.Querydef
Dim loRst as DAO.Recordset

set loDb = Currentdb
Set loQdf = loDb.QueryDefs("YourQuery")
With loQdf
.Parameters(0) = strID
set loRst = .OpenRecordset
End with

In ADO
Dim loDB As ADODB.Connection
Dim loQdf As ADODB.Command
Dim loRst As ADODB.Recordset
Dim strID As String

strID = 1
Set loDB = Application.CurrentProject.Connection
Set loQdf = New ADODB.Command
With loQdf
Set .ActiveConnection = loDB
.CommandText = "YourQuery"
.CommandType = adCmdStoredProc
Set loRst = .Execute(Parameters:=Array("1"))
End With

If your using the query's as recordsources or rowsources then you could

just
create a generic function to return generic variables

Sou you could just have a function
Function QueryParam(Index as long) as Variant
Select Case Index
Case 0
QueryParam = strID
Case 1
QueryParam = lngID
Case 2
QueryParam = dblAnotherVar
' ...
End Select
End function

Or you could programatically change the SQL of the query.
--
Terry Kreft
MVP Microsoft Access
"Sunil Korah" <hb*****@indiatimes.com> wrote in message
news:72**************************@posting.google.c om...
I dont know whether this is a stupid question. But does access have
something akin to the pointer variable in C - or for that matter the
'&' operator in xbase.

I will explain my reason for wanting it too. I often use SQLs in which
the where condition gets the data from a variable. e.g

SELECT * from Customer
WHERE CustID = strID

strID being a public variable. But of course the above SQL does not
work as such, because SQL can't read that variable. So I use a
function like

Public Function GetID()
GetID=strID
End Function

and the actual SQL I use is

SELECT * from Customer
WHERE CustID = GetID()

The problem is, each time I have to write a function. Whereas in xBase
for example I would have a single function like this

Function GetVar
Parameters InVar
GetVar = &InVAr
Return GetVar

so that if I call the function as GetVar(strID) I would get the strID
value.

Any help would be appreciated
Sunil Korah


Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bryan Parkoff | last post by:
I create one 32 Bits variable and four pointer variables. Four pointer variables link or point to one 32 Bits variable. Each pointer variable is 8 Bits. Look at my example below. unsigned int...
20
by: CoolPint | last post by:
While I was reading about const_cast, I got curious and wanted to know if I could modify a constant variable through a pointer which has been "const_cast"ed. Since the pointer would be pointing to...
11
by: J Wang | last post by:
dear, I debug the program recently as follows. #include <sys/stat.h> int main(int argc, char *argv) { struct stat buf;
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
51
by: Kuku | last post by:
What is the difference between a reference and a pointer?
22
by: Jack | last post by:
The following code can be compiled. But When I run it, it causes "Segmentation fault". int main(){ char **c1; *c1 = "HOW"; // LINE1 ++(*c1); *c1 = "ARE";
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
4
by: craig | last post by:
During construction of an object "parent", if you create a subobject that stores a pointer to the parent (through the "this" pointer), will that pointer be valid when the subobject is later called?...
5
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.