• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

Update routine for standard module function

Curently this code works for a form module:
I need to work in module to make a function call.



http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_21499562.html

reference question: above.

Dim rs
Dim pathname, newpathname, itemname, picname As String
pathname = "C:\Images\"
newpathname = "C:\Images\New\"
Me.RecordSource = "SELECT * FROM NoPic_Picture_NotAll" <<<<---error here...invalid use of "me"...
Set rs = Me.Recordset.Clone
rs.MoveFirst
While Not rs.EOF
  itemname = rs!material_no
  picname = rs!primary_image2
  If itemname <> picname Then
    FileCopy pathname & picname, newpathname & itemname & ".JPG"
  End If
  rs.MoveNext
Wend
rs.Close
Set rs = Nothing

This code is used within a form module...


I need to update this to run whithin a standard module please...


Thanks
fordraiders
0
Fordraiders
Asked:
Fordraiders
  • 3
  • 3
  • 3
1 Solution
 
jerryb30Commented:
Why do you need to set a source for a form, since you are going to use the same SQL to create the rs.

Dim rs as dao.recordset
Dim pathname, newpathname, itemname, picname As String
pathname = "C:\Images\"
newpathname = "C:\Images\New\"

Set rs = currentdb.openrecordset("SELECT * FROM NoPic_Picture_NotAll" )
rs.MoveFirst
While Not rs.EOF
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Aside from Jerry's question of 'Why do you need this in a separate code module', which can go a number of directions..

In a separate code module
Public Function fn_whatever (frm as Form) as Whatever

'do your stuff here.  Below is a form reference. 
frm.RecordSource = "SELECT * FROM NoPic_Picture_NotAll" 

End Function

Open in new window

Then in your form, call the function, passing in the form object
Call fn_whatever(Me)

Open in new window

0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>Dim pathname, newpathname, itemname, picname As String
btw, don't do this, as if you don't specify a variable type for EVERY variable, Access will define them as Variants, which could cause unintended errors or other bad stuff to happen.

Dim pathname as String, newpathname as String, itemname as String, picname As String
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
FordraidersAuthor Commented:
jerry, nothing to do with a form anymore...just  a  standard module
0
 
FordraidersAuthor Commented:
i need to just call the procedure from a standard module..

I'm not using a form anymore..

Thanks
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>i need to just call the procedure from a standard module
Okay, but your function has Me.RecordSource, so explain for us how you plan on referencing forms when called from a separate code module.  

Are we talking only one form, or multiple, or some logic that says one or another?
0
 
jerryb30Commented:
To sever the function from any form, just open the recordset using the same sql used as form control source previously. As I posted prior.
0
 
FordraidersAuthor Commented:
Sorry, Jerry answered my question...
Sorry for the oversight.
0
 
jerryb30Commented:
ty
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now