Solved

Update routine for standard module function

Posted on 2013-02-04
9
230 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
 
LVL 3

Author Comment

by:fordraiders
ID: 38851735
jerry, nothing to do with a form anymore...just  a  standard module
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now