Pack a linked DB file

M

Maureen

Can anyone suggest how I might be able to "pack" a linked DBIII file from
within access. I am using access to build the data needed for a label
printer (it can only read DBIII) and currently have to open the printer
utility to pack the database to remove the deleted records. I would like to
eliminate this step by including something that can be called from access
that will look after this. Any suggestions or direction would be
apprecitated!

M
 
J

Joe Fallon

I vaguely recall that there is either a registry setting or an .ini file
setting that hides deleted dBase (and Foxpro) records from Access. Try
searching MSKB or Google for info on this.

Basically, Access should not see deleted records in dBase so you should only
have to pack it whenever you feel like it.
 
M

Maureen

Joe,

Thanks for your post. My issue is not in access - I need to pack the
DB file for the label printig program since it still sees the deleted
records and prints blank labels. Currently we are opening the finished
DB in the label program and packing it before we print. I would like
to eliminate this step by packing the DB as part of the access routine
that creates the data. I suspect there may be some little utility out
there that I can call from access to do the packing.

M
 
J

Joe Fallon

Maureen,
I am a bit confused - how does the dBase file get created?
If Access creates it then just don't include deleted records.

If Access does not create it, then what does?
Doesn't that program have a Pack command in it?


BTW - I don't know how to Pack from Access.
You may be able to Shell out to a Program that does know how to Pack.
Not sure what that gains you.
 
M

Maureen

Joe,

From access a delete query clears thre DB file of the previous job and then
an append query adds the next one. After this is done we have to open the DB
program and pack the records before printing the labels to avoid blank ones.
This is done 20 or 30 times a day and I'd like to automate the whole
proceedure.

If (from access) I create a new DB file the label program can not connect to
it. I have tried DBIII, IV & V with no luck. I created the lable DB using
the DB editior in the lable program and use access to stuff in what I need.
I would like to either 1) pack from access 2) find some way to call the pack
from the DB editor with no intervention 3) find a way to create a new file
each time that the lable program can connect to.

Not sure if this will help shed light??? I have submitted a help request to
lableview as well.

M
 
J

John Nurick

Hi Maureen and Joe,

The standard way of packing a dBASE file is simply to create another one
containing only the records that have not been deleted. But it seems
that there's someting non-standard about the way the label application
uses the dBASE file format, or new files created by Access would just
work.

One way round this might be to write your own code to _empty_ the label
application's file, instead of delete-and-hopefully-pack. The dBASE III
file format isn't very complicated (unless there are memo fields
involved) and there's documentation at www.wotsit.org.

Basically it's just a matter of
-open the .dbf file
-read the length of the file header (which contains field
definitions etc.) which I think is at bytes 8-9
-write the header to a new file, setting the record count (?bytes 4
to 7) to zero and perhaps updating the date stamp (bytes 1-3?)
 
R

Ronald W. Roberts

Maureen said:
Can anyone suggest how I might be able to "pack" a linked DBIII file from
within access. I am using access to build the data needed for a label
printer (it can only read DBIII) and currently have to open the printer
utility to pack the database to remove the deleted records. I would like to
eliminate this step by including something that can be called from access
that will look after this. Any suggestions or direction would be
apprecitated!

M
The only way I can thing of doing this is to create a Visual FoxPro DLL.
Write the DLL so you can pass it the
information it will need to PACK the table. The only problem I see is
one of sharing or the table
being opened by another application and not being allowed to Pack the
table. This may require you to deleting
the link in Access, execute the pack in the DLL, and then relink the
table back into Access.

Ron
 
M

Maureen

Thanks Joe - I'll give it a go!
M

Joe Fallon said:
Yes.
That is a much clearer picture!

Ok here is a way to do it using an old utility program I found on the web.
It looks like a lot of code but just copy/paste where you are supposed to
and it should work.
=================================================================

Code for ShellWait came from here:
http://www.mvps.org/access/api/api0004.htm

=================================================================
Step1:
Create a new Module named Module1 and paste all this code into it and save
it.

Option Compare Database
Option Explicit

'***************** Code Start ******************
'This code was originally written by Terry Kreft.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Terry Kreft
Private Const STARTF_USESHOWWINDOW& = &H1
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&

Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long

Public Sub ShellWait(Pathname As String, Optional WindowStyle As Long)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret As Long
' Initialize the STARTUPINFO structure:
With start
.cb = Len(start)
If Not IsMissing(WindowStyle) Then
.dwFlags = STARTF_USESHOWWINDOW
.wShowWindow = WindowStyle
End If
End With
' Start the shelled application:
ret& = CreateProcessA(0&, Pathname, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
ret& = CloseHandle(proc.hProcess)
End Sub
'***************** Code End ****************

================================================================
Step 2:
 
M

Maureen

Thanks a ton for your help! (and the link - I looked and could not find it).
I have e-mailed label people to see if thier is a command line option.

M
 

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