Solved

Update routine for standard module function

Posted on 2013-02-04
9
234 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
  • 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 65

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 65

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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 65

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 500 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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…

770 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