Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Update routine for standard module function

Posted on 2013-02-04
9
Medium Priority
?
239 Views
Last Modified: 2013-02-04
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
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
9 Comments
 
LVL 26

Expert Comment

by:jerryb30
ID: 38851688
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
 
LVL 66

Expert Comment

by:Jim Horn
ID: 38851694
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
 
LVL 66

Expert Comment

by:Jim Horn
ID: 38851701
>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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 3

Author Comment

by:fordraiders
ID: 38851735
jerry, nothing to do with a form anymore...just  a  standard module
0
 
LVL 3

Author Comment

by:fordraiders
ID: 38851738
i need to just call the procedure from a standard module..

I'm not using a form anymore..

Thanks
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 38851793
>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
 
LVL 26

Accepted Solution

by:
jerryb30 earned 2000 total points
ID: 38852028
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
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 38853008
Sorry, Jerry answered my question...
Sorry for the oversight.
0
 
LVL 26

Expert Comment

by:jerryb30
ID: 38853380
ty
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question