473,471 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

close and reopen db? in vb

365 Contributor
hello,

i want to use the various startup code such as

AllowByPassKey
etc

as you no doubt know this only takes affect after a db restart, i want to force this in code... any ideas how?

my plan is to use command switches to parse a "lock"/"unlock" variable and then restat immediately (if unlock (default would be locked)) and open exclusively.

tnx
dan
Dec 17 '08 #1
26 15540
MMcCarthy
14,534 Recognized Expert Moderator MVP
Hi Dan

This is a property setting and can be controlled as follows:
Expand|Select|Wrap|Line Numbers
  1. ' disable bypass key
  2. SetProperties "AllowBypassKey", dbBoolean, False 
  3. ' enable bypass key
  4. SetProperties "AllowBypassKey", dbBoolean, True 
  5.  
Dec 18 '08 #2
MMcCarthy
14,534 Recognized Expert Moderator MVP
For more advanced information on controlling startup properties check out this msdn article.

Chapter 2: Protecting Your Database with Startup Options
Dec 18 '08 #3
Dan2kx
365 Contributor
im sorry, i already know how to do that bit.

i need to know how to force a restart of currentdb
Dec 18 '08 #4
MMcCarthy
14,534 Recognized Expert Moderator MVP
You could try running a compact and repair which will compact the database and then close and reopen it.

Expand|Select|Wrap|Line Numbers
  1. '------------------------------------
  2. '- Compact the database.  This only -
  3. '- works if it is the only code in  -
  4. '- the function, and if the         -
  5. '- function is called from the last -
  6. '- line of another VB function      -
  7. '------------------------------------
  8. Function CompactandRepairDB()
  9. On Error GoTo Err_CompactDB
  10.  
  11.     CommandBars("Menu Bar"). _
  12.     Controls("Tools"). _
  13.     Controls("Database utilities"). _
  14.     Controls("Compact and repair database..."). _
  15.     accDoDefaultAction
  16.  
  17. Exit_Compactdb:
  18.  
  19.     Exit Function
  20.  
  21. Err_CompactDB:
  22.  
  23.     If Err.Number = 3356 Then
  24.         Resume Exit_Compactdb
  25.     Else
  26.         MsgBox Err.Description
  27.         Resume Exit_Compactdb
  28.     End If
  29.  
  30. End Function
  31.  
Dec 18 '08 #5
Dan2kx
365 Contributor
i used a shell command as such

(simplified)

call shell(strFilename, 1)
docmd.quit

this works but i cannot open the db in exclusive mode because it is still open
any ideas similar?
Dec 18 '08 #6
NeoPa
32,556 Recognized Expert Moderator MVP
You will never be able to call for an exclusive open on a database from within the code of the very same database. That is simply illogical.

You can try to be clever and set something up with a Cmd or Bat file. That won't be too straightforward though, depending on the complexity you want to use.
Dec 18 '08 #7
Dan2kx
365 Contributor
Would you consider it sloppy to open a blank database first and then the original with exclusive rights? would that work?
Dec 18 '08 #8
MMcCarthy
14,534 Recognized Expert Moderator MVP
@Dan2kx
No because as NeoPa says you cannot open "another" database exclusively while you are still in the original database and therefore it is still open.

Remember you are dealing with instances of the database. It doesn't matter if the database is empty or not. It's the application that counts.
Dec 18 '08 #9
Dan2kx
365 Contributor
I meant to open a blank database, close the original and then open the original again with /excl and then close the blank as such;

call shell(blank,1)
docmd.quit
call shell(original /excl)
docmd.quit

therefore the original would not be open.
would that work?
Dec 18 '08 #10
NeoPa
32,556 Recognized Expert Moderator MVP
If the original is not open then the code must have stopped running. ==> no opening of any other database.

Control must be passed to some other process, which in turn, and only after the calling process (original Access database code) has been determined to have completed, may open the original database in exclusive mode.

Does that make sense?
Dec 18 '08 #11
Dan2kx
365 Contributor
mayb...

if i open a blank database with new code to open the first on open that would work!?

or else a batch file then?
if i was to use a batch file how would i get it to wait until access was closed before reopening?
Dec 18 '08 #12
Dan2kx
365 Contributor
yes! works!

so from main db, i have a command switch, if /cmd = "unlock" turn startups back on, open next (blank) database and close main.

autoexec macro in blank db runs code which opens original /excl and closes blank. to slow down the automated process and allow /excl time for first db to close, don't use digital signature on blank db, or add in a msgbox

shell command used as prviously sated.

unless anyone can suggest a better method thaks for the help guys!

Dan out (for now)
Dec 19 '08 #13
NeoPa
32,556 Recognized Expert Moderator MVP
In a CMD file (far better than BAT - although either would work for your requirements) I usually do a simple rename of a file to itself to determine if it is safe to continue.

If that works (NOT ERRORLEVEL = 1) then the file is free to be opened. If not, then loop and try again, optionally prompting the operator to determine if they're still interested.

The beauty of a CMD (or BAT) file is that the actual file can be created on the fly by the database code, precisely defined for the job in hand and without depending on anything external to the database to be left lying around.
Dec 19 '08 #14
Dan2kx
365 Contributor
im afraid i have no real experience with bat/cmd files other than simple tasks, could you point me in a useful direction for this particular requirement? i am attracted to the simplicity rather than my more complicated fix.
Dec 19 '08 #15
NeoPa
32,556 Recognized Expert Moderator MVP
As an working example, and to illustrate all the points I think you'll need, I knocked up a working version below. You may well have to make changes, and you may want to incorporate some flexibility into it (Name of MDB; Folder path; etc), but fundamentally this is what you need.
TestMDB.Cmd
Expand|Select|Wrap|Line Numbers
  1. CD /D %HomePath%
  2.  
  3. :CheckLoop
  4. Ren MyDB.Mdb MyDB.Mdb
  5. If ErrorLevel 1 GoTo CheckLoop
  6.  
  7. MyDB.Mdb
Dec 20 '08 #16
NeoPa
32,556 Recognized Expert Moderator MVP
As a sort of PS I googled "cmd tricks" and found Coding Horror: Stupid Command Prompt Tricks. Typing HELP on the command line is one of the basic ways of learning what you can do with it. It has a couple of other tips too though.

Everything else I found seemed to be cracking related so I won't send you in that direction.
Dec 20 '08 #17
Dan2kx
365 Contributor
I am using a UNC (\\DataDrive\Folder) path to locate my DB and this throws a spanner in the works for CMD file?
Dec 23 '08 #18
NeoPa
32,556 Recognized Expert Moderator MVP
It shouldn't be that much of a problem. The example I used was simply an example. Try instead something similar to :
TestMDB.Cmd
Expand|Select|Wrap|Line Numbers
  1. :CheckLoop
  2. Ren \\DataDrive\Folder\MyDB.Mdb MyDB.Mdb
  3. If ErrorLevel 1 GoTo CheckLoop
  4.  
  5. \\DataDrive\Folder\MyDB.Mdb
Dec 23 '08 #19
Dan2kx
365 Contributor
I dont mean to keep throwing up new obsticles... but i am using a hidden folder and it doesnt seem to work..
Dec 23 '08 #20
NeoPa
32,556 Recognized Expert Moderator MVP
I think you need to give more information.

Hidden folders don't automatically stop access. They're simply not displayed by default (when browsing). What is your specific problem here?
Dec 23 '08 #21
Dan2kx
365 Contributor
my file path is
\\nlg-plwardv1\holiday$\holidays.mdb
i tried your .cmd solution but got a "file not found error"
i dont really wantto map the drive

cheers
and sorry for being difficult

Dan
Dec 24 '08 #22
NeoPa
32,556 Recognized Expert Moderator MVP
This doesn't look like an issue with hidden shares to me. I've just run a test on viewing the contents of a hidden share and it worked perfectly as expected.

What response do you get when you run (from a command prompt) ?
Expand|Select|Wrap|Line Numbers
  1. DIR \\nlg-plwardv1\holiday$
Dec 24 '08 #23
Dan2kx
365 Contributor
ok the file is not visible (that is hidden too) could that be the problem then?
Dec 24 '08 #24
NeoPa
32,556 Recognized Expert Moderator MVP
Oh yes ;)
Dec 24 '08 #25
Dan2kx
365 Contributor
im having some trouble with a command file (that is written from access vb module)

Expand|Select|Wrap|Line Numbers
  1. CheckLoop1:
  2. Copy \\nlg-plwardv1\Holiday$\ShiftInfo.txt \\nlg-plwardv1\holiday$\ShiftInfo.txt /y
  3. If ErrorLevel 1 GoTo CheckLoop1
  4. Checkloop2:
  5. \\nlg-plwardv1\holiday$\ShiftInfo.txt
  6. If ErrorLevel 1 GoTo CheckLoop2
  7. Checkloop3:
  8. Del \\nlg-plwardv1\holiday$\Update.cmd /f
  9. If ErrorLevel 1 GoTo CheckLoop3
  10.  
can anyone see any errors with this? doesnt do anything as far as i can tell
the last line is for deleting itself

this is just a tester ATM, i plan to use the code to pull the current version of an MDE if the one that is running is out of date (on open).
Cheers
Jan 30 '09 #26
Dan2kx
365 Contributor
figured it out had colon in wrong place

Expand|Select|Wrap|Line Numbers
  1. :CheckLoop
Feb 1 '09 #27

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: KaXo | last post by:
$r_socket = IO::Socket::INET->new( PeerAddr => "10.0.26.78", PeerPort => 17990, Proto => 'tcp', Timeout => 1 ); ...................... if ($r_socket && $r_socket->connected()) {...
19
by: Lauren Wilson | last post by:
A2K app: Question: is the flagged line (<<<) below necessary. If that line is needed, what effect does it have (if any) on the fact that the very same database is the linked back end db? ...
1
by: Agnes | last post by:
In my one form, the user need to search many field, e.g customer name, country name, currency.. etc They are using the same conMaster , So, when Should I closed the connection ?? 1st) if the user...
5
by: Generic Usenet Account | last post by:
I have been able to recreate a problem that I am having with the file stream using the simple sample code given below. I am trying to read the number of lines in a file, relying on the getline...
2
by: Marc | last post by:
I'm building a Windows service that writes log messages via TraceListeners. I assume Trace.Close() is useful for garbage collection, but I'm not sure where to call it in the Windows service. Any...
54
by: Zytan | last post by:
I have a log class that makes a synchronized TextWriter like so, in the constructor: StreamWriter sw = new StreamWriter(filename); tw = TextWriter.Synchronized(sw); In the destructor,...
20
by: raddrummer | last post by:
Hi there, I'm woking on a function that takes the input from a form (including Payroll Contact), uses it as a query parameter, runs the query, and then emaills out a custom .xls file using the...
1
by: =?Utf-8?B?Skw=?= | last post by:
HI, I have this problem since yesterday. Every time I try to close Outlook, I can't, I get the error"MS Outlook has encountered a problem and needs to close. we are sorry.... Just that it...
18
by: Eric B. | last post by:
Is it a bad idea to do both once I'm done with an object? Eric B.
0
by: PJ6 | last post by:
OK this is annoying... after I installed VS2008 to try it out, apparently an update was made to the behavior VS2005. Now when I close and reopen a document I'm working on, the Undo history is...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.