Class Modual Help

B

Blair

In a Class Modual up at the very top I have This

Option Compare Database
Option Explicit
Public Sections As Integer
Public Try As Integer
Public OneDay As Integer
Public NineDay As Integer
Public TenDay As Integer
Public TwelveDay As Integer
Public RemateDateDay As Integer
Public RemateDate As Date
Private FarmName As String

Further down I have a Private sub like this

Private Sub Form_Load()

Open "Number Of Section's" For Random As #9 Len = 50
Get #9, 9, Sections
Close #9
Text20 = Sections

Open "Try" For Random As #8 Len = 50
Get #8, 8, Try
Close #8
Combo64 = Try

Open "1 Day Remates" For Random As #7 Len = 50
Get #7, 7, OneDay
Close #7
Combo11 = OneDay
Text22 = OneDay

Open "9 Day Remates" For Random As #6 Len = 50
Get #6, 6, NineDay
Close #6
Combo58 = NineDay
Text24 = NineDay

Open "10 Day Remates" For Random As #5 Len = 50
Get #5, 5, TenDay
Close #5
Combo60 = TenDay
Text26 = TenDay

Open "12 Day Remates" For Random As #4 Len = 50
Get #4, 4, TwelveDay
Close #4
Combo62 = TwelveDay
Text27 = TwelveDay

Open "Remate Date Day" For Random As #3 Len = 50
Get #3, 3, RemateDateDay
Close #3
Text14 = RemateDateDay

Open "Remate Date" For Random As #2 Len = 50
Get #2, 2, RemateDate
Close #2
Text12 = RemateDate

Open "Farm Name" For Random As #1 Len = 50
Get #1, 1, FarmName
Close #1
Text1 = FarmName

End Sub

And another like this!

Private Sub Text1_AfterUpdate()
FarmName = Text1
Open "Farm Name" For Random As #1 Len = 50


Put #1, 1, FarmName

Close #1 ' Close file.

End Sub

This code some how saves the farm name somehow to a file and then retrieves
it on form load to show the farm name.
NOW MY PROBLEM!
When I copy the program db to another folder or drive to use it for another
farm and I change the name in one program it changes in both copys. So for
some reason both copys of the db is using the same common file to save the
name. So I am hoping someone can tell me how to segregate the two db to use
two different files, one for each farm.
Does anyone understand this code and how it works, I can't get a hold of
the guy that wrote it and I don't know enough to figure it out.

Thanks Blair
 
D

Douglas J. Steele

No offense, but that code is terrible!

For one thing, file numbers should never be hard-coded: you should always
use the FreeFile function to determine what file number to use. Also, the
file names don't have full paths, so you really have no control over where
they're being read from. Without a full path, Access is going to look in the
current directory. If you open the application by double-clicking on the MDB
through Windows Explorer, the current directory will (probably) be that
user's My Documents folder (unless the default has been changed). If you
open the application by opening Access, choosing File | Open and navigating
to the MDB file, the current directory will be the folder where the MDB
exists. If you open the application using a shortcut, the current directory
will be wherever the shortcut says it is.

If your current directory isn't changing each time you open the application,
then you're likely using the same 9 files regardless of which application
you're using.

You could change that module to use a single INI file for each application,
rather than having 9 separate files. Name the INI file the same as the
application (replacing the MDB extension with the INI extension), and put it
in the same folder as the MDB. Randy Birch has a good introduction to
working with INI files at http://vbnet.mvps.org/code/file/pprofilebasic.htm
(Obligatory warning: Randy's site is aimed at Visual Basic programmers.
There are significant differences between the controls available for Visual
Basic forms and Access forms, so sometimes his samples don't port directly
to Access. I took a quick look at this particular example, and I think it
should be okay in Access)
 
B

Blair Mullen

Thankyou for clearing things up, Your coment was not a surprise, though I am
not able to do it on my own and this is what I inherited to start with. Now
I understand what is hapening I may be able to work around it till I can
make it better
Thanks a whole bunch

PS noticed Canada.com in your email. are you one of us?
if so where in Canada
Thanks again Blair
 
R

rkc

Blair said:
Thankyou for clearing things up, Your coment was not a surprise, though I am
not able to do it on my own and this is what I inherited to start with. Now
I understand what is hapening I may be able to work around it till I can
make it better


This is a quick fix until you get around to a complete re-write.
The current code is functional, but as Doug Steele pointed out,
there are other problems lurking in the shadows.

Place the following code in a code module:

'******************** Code Begin ****************
'Code courtesy of
'Terry Kreft & Ken Getz
'
Function CurrentDBDir() As String
Dim strDBPath As String
Dim strDBFile As String
strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)
CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
End Function
'******************** Code End ****************


With that done alter the file names in each of the open statements
like so:

Open CurrentDBDir & "Try" For Random As #8 Len = 50
Get #8, 8, Try
Close #8
Combo64 = Try
 
B

Blair Mullen

Thanks I'll try that
Blair
rkc said:
This is a quick fix until you get around to a complete re-write.
The current code is functional, but as Doug Steele pointed out,
there are other problems lurking in the shadows.

Place the following code in a code module:

'******************** Code Begin ****************
'Code courtesy of
'Terry Kreft & Ken Getz
'
Function CurrentDBDir() As String
Dim strDBPath As String
Dim strDBFile As String
strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)
CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
End Function
'******************** Code End ****************


With that done alter the file names in each of the open statements
like so:

Open CurrentDBDir & "Try" For Random As #8 Len = 50
Get #8, 8, Try
Close #8
Combo64 = Try
 
R

rkc

Blair said:
Thanks I'll try that
Blair

Backup whatever you need to first. If you really don't know
where the current files are being written you should do a
file search, find them and create backups also.

Never blindly use code posted in a news group without taking
pre-cautions to undo any possible damage.
 
F

Fred Boer

Dear Doug:

Toronto? For some reason I thought you lived in the Republic of Alberta!
Maybe I thought this because you work for an "oil company", who knows? I
guess I'll have to move your push-pin on the map in my shrine... ;)

Happy New Year!
Fred Boer
 
B

Blair Mullen

Thanks for the warning, I'v already been down that road in the past. But for
some reason there is allways that urge to gamble on "it will work this
time".
I found the files they live in{My Documents} and if I delete them, they
restore or make new ones when I open the db. Now there is no data saved in
the files until I set it up, but it is just the farm name and other default
setings that you choose depending on your own preferences.

Thanks for your help and warning
Blair
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top