Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

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.



https://www.experts-exchange.com/questions/21499562/Use-jpg-files-and-create-new-jpg-files-for-non-duplicate-names-Using-Table-data.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
Avatar of jerryb30
jerryb30
Flag of United States of America image

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
Avatar of Jim Horn
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

>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
Avatar of Fordraiders

ASKER

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

I'm not using a form anymore..

Thanks
>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?
ASKER CERTIFIED SOLUTION
Avatar of jerryb30
jerryb30
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, Jerry answered my question...
Sorry for the oversight.