call procedures in a Subform using variables

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm trying to call a subform function from a module.
I was using this instruction:

Forms(form_name)![subform_name].Form.function_name

The problem is that I would like the subform_name to be a variable...

Please give me a help

Thanks...
 
Hi!

It´s a little bit tricky to understand what you are trying to acomplishe
here. So please give us more information.

What do you want the function to do?

To be able to use a function or sub in a form you need to store the
function/sub in a code module instead of in a form code moduel. And you need
to declare it as public.

Please give us more information of what you are trying to do!

// Niklas
 
Ok!

I have a form that includes many subforms
Each subform is linked to a different table.
When I open the form, the code written on the module checks each of the
subform's tables and decides whether to update or not its table.
Now, the function I'm trying to call from the module is written in each
subform code (the function name iis the same for every subform, but its
content is different), that's why I need to call the function using the
subform name being a variable depending on which subform's table needs
update...

I hope I've been clearer enough....
Thanks...


Niklas Östrergren said:
Hi!

It´s a little bit tricky to understand what you are trying to acomplishe
here. So please give us more information.

What do you want the function to do?

To be able to use a function or sub in a form you need to store the
function/sub in a code module instead of in a form code moduel. And you need
to declare it as public.

Please give us more information of what you are trying to do!

// Niklas


Tiago Pinto said:
Hi,

I'm trying to call a subform function from a module.
I was using this instruction:

Forms(form_name)![subform_name].Form.function_name

The problem is that I would like the subform_name to be a variable...

Please give me a help

Thanks...
 
What does the functions do? Can you post an example?

// Niklas

Tiago Pinto said:
Ok!

I have a form that includes many subforms
Each subform is linked to a different table.
When I open the form, the code written on the module checks each of the
subform's tables and decides whether to update or not its table.
Now, the function I'm trying to call from the module is written in each
subform code (the function name iis the same for every subform, but its
content is different), that's why I need to call the function using the
subform name being a variable depending on which subform's table needs
update...

I hope I've been clearer enough....
Thanks...


Niklas Östrergren said:
Hi!

It´s a little bit tricky to understand what you are trying to acomplishe
here. So please give us more information.

What do you want the function to do?

To be able to use a function or sub in a form you need to store the
function/sub in a code module instead of in a form code moduel. And you need
to declare it as public.

Please give us more information of what you are trying to do!

// Niklas


Tiago Pinto said:
Hi,

I'm trying to call a subform function from a module.
I was using this instruction:

Forms(form_name)![subform_name].Form.function_name

The problem is that I would like the subform_name to be a variable...

Please give me a help

Thanks...
 
OK!!!

Note that I'm only having trouble about the syntax in the instruction
Forms(form_name)![subform_name].Form.update(period)

But here it goes....

Function update(period As String)

Dim bd_update As Database
Dim qdf_update As QueryDef
Dim rst_update As Recordset

Set bd_update = CurrentDb

Set qdf_update = bd_update.CreateQueryDef("", SQL instruction to query
external database ")

Set rst_update = qdf_update.OpenRecordset()

With rst_update
Do While Not .EOF
DoCmd.RunSQL (" SQL instruction to INSERT records in table ")
.MoveNext
Loop
.Close
End With

End Function


Niklas Östrergren said:
What does the functions do? Can you post an example?

// Niklas

Tiago Pinto said:
Ok!

I have a form that includes many subforms
Each subform is linked to a different table.
When I open the form, the code written on the module checks each of the
subform's tables and decides whether to update or not its table.
Now, the function I'm trying to call from the module is written in each
subform code (the function name iis the same for every subform, but its
content is different), that's why I need to call the function using the
subform name being a variable depending on which subform's table needs
update...

I hope I've been clearer enough....
Thanks...


Niklas Östrergren said:
Hi!

It´s a little bit tricky to understand what you are trying to acomplishe
here. So please give us more information.

What do you want the function to do?

To be able to use a function or sub in a form you need to store the
function/sub in a code module instead of in a form code moduel. And you need
to declare it as public.

Please give us more information of what you are trying to do!

// Niklas


Hi,

I'm trying to call a subform function from a module.
I was using this instruction:

Forms(form_name)![subform_name].Form.function_name

The problem is that I would like the subform_name to be a variable...

Please give me a help

Thanks...
 
OK!

Try makin the function Public:

Public Function update(period As String)


End Function

And call the function like this:

update(period)

But if I´m not totally out of line you need to place the function/functions
in a standard code module and not in a form code module. Besides I asume
that period in update(period) is a varaible that have been declared
somewhere and appended a value. You don´t specifye this so I asume that so
is the case.

Do you get any runtime error when you try to run your code?

// Niklas

Tiago Pinto said:
OK!!!

Note that I'm only having trouble about the syntax in the instruction
Forms(form_name)![subform_name].Form.update(period)

But here it goes....

Function update(period As String)

Dim bd_update As Database
Dim qdf_update As QueryDef
Dim rst_update As Recordset

Set bd_update = CurrentDb

Set qdf_update = bd_update.CreateQueryDef("", SQL instruction to query
external database ")

Set rst_update = qdf_update.OpenRecordset()

With rst_update
Do While Not .EOF
DoCmd.RunSQL (" SQL instruction to INSERT records in table ")
.MoveNext
Loop
.Close
End With

End Function


Niklas Östrergren said:
What does the functions do? Can you post an example?

// Niklas

Tiago Pinto said:
Ok!

I have a form that includes many subforms
Each subform is linked to a different table.
When I open the form, the code written on the module checks each of the
subform's tables and decides whether to update or not its table.
Now, the function I'm trying to call from the module is written in each
subform code (the function name iis the same for every subform, but its
content is different), that's why I need to call the function using the
subform name being a variable depending on which subform's table needs
update...

I hope I've been clearer enough....
Thanks...


:

Hi!

It´s a little bit tricky to understand what you are trying to acomplishe
here. So please give us more information.

What do you want the function to do?

To be able to use a function or sub in a form you need to store the
function/sub in a code module instead of in a form code moduel. And
you
need
to declare it as public.

Please give us more information of what you are trying to do!

// Niklas


Hi,

I'm trying to call a subform function from a module.
I was using this instruction:

Forms(form_name)![subform_name].Form.function_name

The problem is that I would like the subform_name to be a variable...

Please give me a help

Thanks...
 
This is funny:
Now I'm receiving this Run-Time Error 3014:
Cannot open more tables....

Rookie stuff for sure :)
can you gimme an hand with this first...


Niklas Östrergren said:
OK!

Try makin the function Public:

Public Function update(period As String)


End Function

And call the function like this:

update(period)

But if I´m not totally out of line you need to place the function/functions
in a standard code module and not in a form code module. Besides I asume
that period in update(period) is a varaible that have been declared
somewhere and appended a value. You don´t specifye this so I asume that so
is the case.

Do you get any runtime error when you try to run your code?

// Niklas

Tiago Pinto said:
OK!!!

Note that I'm only having trouble about the syntax in the instruction
Forms(form_name)![subform_name].Form.update(period)

But here it goes....

Function update(period As String)

Dim bd_update As Database
Dim qdf_update As QueryDef
Dim rst_update As Recordset

Set bd_update = CurrentDb

Set qdf_update = bd_update.CreateQueryDef("", SQL instruction to query
external database ")

Set rst_update = qdf_update.OpenRecordset()

With rst_update
Do While Not .EOF
DoCmd.RunSQL (" SQL instruction to INSERT records in table ")
.MoveNext
Loop
.Close
End With

End Function


Niklas Östrergren said:
What does the functions do? Can you post an example?

// Niklas

Ok!

I have a form that includes many subforms
Each subform is linked to a different table.
When I open the form, the code written on the module checks each of the
subform's tables and decides whether to update or not its table.
Now, the function I'm trying to call from the module is written in each
subform code (the function name iis the same for every subform, but its
content is different), that's why I need to call the function using the
subform name being a variable depending on which subform's table needs
update...

I hope I've been clearer enough....
Thanks...


:

Hi!

It´s a little bit tricky to understand what you are trying to acomplishe
here. So please give us more information.

What do you want the function to do?

To be able to use a function or sub in a form you need to store the
function/sub in a code module instead of in a form code moduel. And you
need
to declare it as public.

Please give us more information of what you are trying to do!

// Niklas


Hi,

I'm trying to call a subform function from a module.
I was using this instruction:

Forms(form_name)![subform_name].Form.function_name

The problem is that I would like the subform_name to be a variable...

Please give me a help

Thanks...
 
Sorry I have looked for this and the only thing I can come up with is the
article belowe:

http://www.mvps.org/access/bugs/bugs0010.htm


I havn´t had this error before so I don´t have any info about it in my small
error code db, sorry! If you don´t get any help out of the article post a
new msg. just about this problem and maby someone else can help you out.
Sorry!

// Niklas


Tiago Pinto said:
This is funny:
Now I'm receiving this Run-Time Error 3014:
Cannot open more tables....

Rookie stuff for sure :)
can you gimme an hand with this first...


Niklas Östrergren said:
OK!

Try makin the function Public:

Public Function update(period As String)


End Function

And call the function like this:

update(period)

But if I´m not totally out of line you need to place the function/functions
in a standard code module and not in a form code module. Besides I asume
that period in update(period) is a varaible that have been declared
somewhere and appended a value. You don´t specifye this so I asume that so
is the case.

Do you get any runtime error when you try to run your code?

// Niklas

Tiago Pinto said:
OK!!!

Note that I'm only having trouble about the syntax in the instruction
Forms(form_name)![subform_name].Form.update(period)

But here it goes....

Function update(period As String)

Dim bd_update As Database
Dim qdf_update As QueryDef
Dim rst_update As Recordset

Set bd_update = CurrentDb

Set qdf_update = bd_update.CreateQueryDef("", SQL instruction to query
external database ")

Set rst_update = qdf_update.OpenRecordset()

With rst_update
Do While Not .EOF
DoCmd.RunSQL (" SQL instruction to INSERT records in table ")
.MoveNext
Loop
.Close
End With

End Function


:

What does the functions do? Can you post an example?

// Niklas

Ok!

I have a form that includes many subforms
Each subform is linked to a different table.
When I open the form, the code written on the module checks each
of
the
subform's tables and decides whether to update or not its table.
Now, the function I'm trying to call from the module is written in each
subform code (the function name iis the same for every subform,
but
its
content is different), that's why I need to call the function
using
the
subform name being a variable depending on which subform's table needs
update...

I hope I've been clearer enough....
Thanks...


:

Hi!

It´s a little bit tricky to understand what you are trying to acomplishe
here. So please give us more information.

What do you want the function to do?

To be able to use a function or sub in a form you need to store the
function/sub in a code module instead of in a form code moduel.
And
you
need
to declare it as public.

Please give us more information of what you are trying to do!

// Niklas


Hi,

I'm trying to call a subform function from a module.
I was using this instruction:

Forms(form_name)![subform_name].Form.function_name

The problem is that I would like the subform_name to be a variable...

Please give me a help

Thanks...
 
Guys,

PMFJI, but I suspect it may have to do with the fact that you are
creating recordsets which you are not resetting. Add these two lines
right before the End Function line:

Set rst_update = Nothing
Set bd_update = Nothing

It might help to do the same with qdf_update as well, I don't know, I
have not encountered it.

HTH,
Nikos
Sorry I have looked for this and the only thing I can come up with is the
article belowe:

http://www.mvps.org/access/bugs/bugs0010.htm


I havn´t had this error before so I don´t have any info about it in my small
error code db, sorry! If you don´t get any help out of the article post a
new msg. just about this problem and maby someone else can help you out.
Sorry!

// Niklas


This is funny:
Now I'm receiving this Run-Time Error 3014:
Cannot open more tables....

Rookie stuff for sure :)
can you gimme an hand with this first...


:

OK!

Try makin the function Public:

Public Function update(period As String)


End Function

And call the function like this:

update(period)

But if I´m not totally out of line you need to place the
function/functions
in a standard code module and not in a form code module. Besides I asume
that period in update(period) is a varaible that have been declared
somewhere and appended a value. You don´t specifye this so I asume that
so
is the case.

Do you get any runtime error when you try to run your code?

// Niklas


OK!!!

Note that I'm only having trouble about the syntax in the instruction
Forms(form_name)![subform_name].Form.update(period)

But here it goes....

Function update(period As String)

Dim bd_update As Database
Dim qdf_update As QueryDef
Dim rst_update As Recordset

Set bd_update = CurrentDb

Set qdf_update = bd_update.CreateQueryDef("", SQL instruction to query
external database ")

Set rst_update = qdf_update.OpenRecordset()

With rst_update
Do While Not .EOF
DoCmd.RunSQL (" SQL instruction to INSERT records in table
")
.MoveNext
Loop
.Close
End With

End Function


:


What does the functions do? Can you post an example?

// Niklas

"Tiago Pinto" <Tiago (e-mail address removed)> wrote in
message
Ok!

I have a form that includes many subforms
Each subform is linked to a different table.
When I open the form, the code written on the module checks each
of
the

subform's tables and decides whether to update or not its table.
Now, the function I'm trying to call from the module is written in

each

subform code (the function name iis the same for every subform,
but
its

content is different), that's why I need to call the function
using
the

subform name being a variable depending on which subform's table
needs
update...

I hope I've been clearer enough....
Thanks...


:


Hi!

It´s a little bit tricky to understand what you are trying to

acomplishe

here. So please give us more information.

What do you want the function to do?

To be able to use a function or sub in a form you need to store
the
function/sub in a code module instead of in a form code moduel.
And
you

need

to declare it as public.

Please give us more information of what you are trying to do!

// Niklas



message


Hi,

I'm trying to call a subform function from a module.
I was using this instruction:

Forms(form_name)![subform_name].Form.function_name

The problem is that I would like the subform_name to be a

variable...

Please give me a help

Thanks...
 
Niklas,

I've solved all my problems:

about the 3014 run-time - I was opening a recordset without closing it...

about the subform problem:
the instruction i have to use is:
Forms(form_name)!Forms(subform_name).Form.update(period)

this way the "subform_name" can be a variable....

Thanks for your help
Sorry for my ability to explain my problem
Hope not having confuse you for the rest of the day....:)


Niklas Östrergren said:
Sorry I have looked for this and the only thing I can come up with is the
article belowe:

http://www.mvps.org/access/bugs/bugs0010.htm


I havn´t had this error before so I don´t have any info about it in my small
error code db, sorry! If you don´t get any help out of the article post a
new msg. just about this problem and maby someone else can help you out.
Sorry!

// Niklas


Tiago Pinto said:
This is funny:
Now I'm receiving this Run-Time Error 3014:
Cannot open more tables....

Rookie stuff for sure :)
can you gimme an hand with this first...


Niklas Östrergren said:
OK!

Try makin the function Public:

Public Function update(period As String)


End Function

And call the function like this:

update(period)

But if I´m not totally out of line you need to place the function/functions
in a standard code module and not in a form code module. Besides I asume
that period in update(period) is a varaible that have been declared
somewhere and appended a value. You don´t specifye this so I asume that so
is the case.

Do you get any runtime error when you try to run your code?

// Niklas

OK!!!

Note that I'm only having trouble about the syntax in the instruction
Forms(form_name)![subform_name].Form.update(period)

But here it goes....

Function update(period As String)

Dim bd_update As Database
Dim qdf_update As QueryDef
Dim rst_update As Recordset

Set bd_update = CurrentDb

Set qdf_update = bd_update.CreateQueryDef("", SQL instruction to query
external database ")

Set rst_update = qdf_update.OpenRecordset()

With rst_update
Do While Not .EOF
DoCmd.RunSQL (" SQL instruction to INSERT records in table ")
.MoveNext
Loop
.Close
End With

End Function


:

What does the functions do? Can you post an example?

// Niklas

Ok!

I have a form that includes many subforms
Each subform is linked to a different table.
When I open the form, the code written on the module checks each of
the
subform's tables and decides whether to update or not its table.
Now, the function I'm trying to call from the module is written in
each
subform code (the function name iis the same for every subform, but
its
content is different), that's why I need to call the function using
the
subform name being a variable depending on which subform's table needs
update...

I hope I've been clearer enough....
Thanks...


:

Hi!

It´s a little bit tricky to understand what you are trying to
acomplishe
here. So please give us more information.

What do you want the function to do?

To be able to use a function or sub in a form you need to store the
function/sub in a code module instead of in a form code moduel. And
you
need
to declare it as public.

Please give us more information of what you are trying to do!

// Niklas


message
Hi,

I'm trying to call a subform function from a module.
I was using this instruction:

Forms(form_name)![subform_name].Form.function_name

The problem is that I would like the subform_name to be a
variable...

Please give me a help

Thanks...
 
Hi Nikos!

Yes, you are right here I think!

I have been away for a while and should have seen this but I didn´t. It
seams as a logic explanation.

// Niklas


Nikos Yannacopoulos said:
Guys,

PMFJI, but I suspect it may have to do with the fact that you are
creating recordsets which you are not resetting. Add these two lines
right before the End Function line:

Set rst_update = Nothing
Set bd_update = Nothing

It might help to do the same with qdf_update as well, I don't know, I
have not encountered it.

HTH,
Nikos
Sorry I have looked for this and the only thing I can come up with is the
article belowe:

http://www.mvps.org/access/bugs/bugs0010.htm


I havn´t had this error before so I don´t have any info about it in my small
error code db, sorry! If you don´t get any help out of the article post a
new msg. just about this problem and maby someone else can help you out.
Sorry!

// Niklas


This is funny:
Now I'm receiving this Run-Time Error 3014:
Cannot open more tables....

Rookie stuff for sure :)
can you gimme an hand with this first...


:


OK!

Try makin the function Public:

Public Function update(period As String)


End Function

And call the function like this:

update(period)

But if I´m not totally out of line you need to place the
function/functions

in a standard code module and not in a form code module. Besides I asume
that period in update(period) is a varaible that have been declared
somewhere and appended a value. You don´t specifye this so I asume that
so

is the case.

Do you get any runtime error when you try to run your code?

// Niklas


OK!!!

Note that I'm only having trouble about the syntax in the instruction
Forms(form_name)![subform_name].Form.update(period)

But here it goes....

Function update(period As String)

Dim bd_update As Database
Dim qdf_update As QueryDef
Dim rst_update As Recordset

Set bd_update = CurrentDb

Set qdf_update = bd_update.CreateQueryDef("", SQL instruction to query
external database ")

Set rst_update = qdf_update.OpenRecordset()

With rst_update
Do While Not .EOF
DoCmd.RunSQL (" SQL instruction to INSERT records in table
")

.MoveNext
Loop
.Close
End With

End Function


:


What does the functions do? Can you post an example?

// Niklas

message


Ok!

I have a form that includes many subforms
Each subform is linked to a different table.
When I open the form, the code written on the module checks each
of

the

subform's tables and decides whether to update or not its table.
Now, the function I'm trying to call from the module is written in

each

subform code (the function name iis the same for every subform,
but

its

content is different), that's why I need to call the function
using

the

subform name being a variable depending on which subform's table
needs

update...

I hope I've been clearer enough....
Thanks...


:


Hi!

It´s a little bit tricky to understand what you are trying to

acomplishe

here. So please give us more information.

What do you want the function to do?

To be able to use a function or sub in a form you need to store
the

function/sub in a code module instead of in a form code moduel.
And

you

need

to declare it as public.

Please give us more information of what you are trying to do!

// Niklas



message


Hi,

I'm trying to call a subform function from a module.
I was using this instruction:

Forms(form_name)![subform_name].Form.function_name

The problem is that I would like the subform_name to be a

variable...

Please give me a help

Thanks...
 
Glad to here that your problem are solved, even if I could´nt be to any help
this time!

// Niklas


Tiago Pinto said:
Niklas,

I've solved all my problems:

about the 3014 run-time - I was opening a recordset without closing it...

about the subform problem:
the instruction i have to use is:
Forms(form_name)!Forms(subform_name).Form.update(period)

this way the "subform_name" can be a variable....

Thanks for your help
Sorry for my ability to explain my problem
Hope not having confuse you for the rest of the day....:)


Niklas Östrergren said:
Sorry I have looked for this and the only thing I can come up with is the
article belowe:

http://www.mvps.org/access/bugs/bugs0010.htm


I havn´t had this error before so I don´t have any info about it in my small
error code db, sorry! If you don´t get any help out of the article post a
new msg. just about this problem and maby someone else can help you out.
Sorry!

// Niklas


Tiago Pinto said:
This is funny:
Now I'm receiving this Run-Time Error 3014:
Cannot open more tables....

Rookie stuff for sure :)
can you gimme an hand with this first...


:

OK!

Try makin the function Public:

Public Function update(period As String)


End Function

And call the function like this:

update(period)

But if I´m not totally out of line you need to place the function/functions
in a standard code module and not in a form code module. Besides I asume
that period in update(period) is a varaible that have been declared
somewhere and appended a value. You don´t specifye this so I asume
that
so
is the case.

Do you get any runtime error when you try to run your code?

// Niklas

OK!!!

Note that I'm only having trouble about the syntax in the instruction
Forms(form_name)![subform_name].Form.update(period)

But here it goes....

Function update(period As String)

Dim bd_update As Database
Dim qdf_update As QueryDef
Dim rst_update As Recordset

Set bd_update = CurrentDb

Set qdf_update = bd_update.CreateQueryDef("", SQL instruction to query
external database ")

Set rst_update = qdf_update.OpenRecordset()

With rst_update
Do While Not .EOF
DoCmd.RunSQL (" SQL instruction to INSERT records in
table
")
.MoveNext
Loop
.Close
End With

End Function


:

What does the functions do? Can you post an example?

// Niklas

Ok!

I have a form that includes many subforms
Each subform is linked to a different table.
When I open the form, the code written on the module checks
each
of
the
subform's tables and decides whether to update or not its table.
Now, the function I'm trying to call from the module is written in
each
subform code (the function name iis the same for every
subform,
but
its
content is different), that's why I need to call the function using
the
subform name being a variable depending on which subform's
table
needs
update...

I hope I've been clearer enough....
Thanks...


:

Hi!

It´s a little bit tricky to understand what you are trying to
acomplishe
here. So please give us more information.

What do you want the function to do?

To be able to use a function or sub in a form you need to
store
the
function/sub in a code module instead of in a form code
moduel.
And
you
need
to declare it as public.

Please give us more information of what you are trying to do!

// Niklas


message
Hi,

I'm trying to call a subform function from a module.
I was using this instruction:

Forms(form_name)![subform_name].Form.function_name

The problem is that I would like the subform_name to be a
variable...

Please give me a help

Thanks...
 
Back
Top