I got this code from Ciurly a while back, and thought it worked fine.
But unfortunately, my ignorance of setting up the SaveDialog options, led to a near disaster.
I was struggling with a problem of why the Access database fell over corrupted with 'unrecognised database' error (unrecoverble too) - when fortunately the user found another bug that sent this code in to a loop.
Unravelling it I found that because I had set the 'InitialDir' to the app folder (as I didn't know what letter the USB drive would be) when the user tested it (without a USB key present) she still clicked 'Save' instead of Cancel to exit. The code then attempted to save the .mdb file to the one that was in use. This caused the loop with 'bookmark error' etc. and also the next time opening - a corrupt database! Lucky she found the second error...or I'd still be looking.
So now I've changed the SaveDialog InitialDir to M: (arbitrary - it shows as blank folder in the Save dialog) to force the user to choose a suitable location. (Filename.ext is supplied)
However, this code still shows the 'Backup Successfull' message and gives the appearance of working - even when a folder / Drive destintion is not provided, and I need to trap that.
(the 'if sSavedialog1.execute' then line doesn't appear to prevent saving if the file name is provided?)
1. Is setting the correct filename.ext as filename, but the M: drive accepatble prcatice?
(I didn't want to set it as E:\ as unpredictable if a printer with USB or such, is connected and taking drive E:\ and might error)
2. How do I trap the blank drive / no drive selected error with a message?
3. Is there any way of prohibiting the file being saved to C:\No25Data? (this seems to cause the corruption)
(the only savedialog options I've changed are FileName=No25ContactData.m
db - Filter MDB Files (*.mdb) |*. mdb - InitialDir=M: .
I would beg your indulgence for answers in code format if poss please - I'm a novice and don't understand all the routines you guys sometimes offer and accept as given.
procedure TFrameBar7.sBitBtn1Click(Sender: TObject);
fileSource, fileDest: string;
if sSavedialog1.execute then// only save if user actually selected a file
fileSource := 'C:\No25Data\No25ContactData.mdb';
CopyFile(PChar(fileSource), PChar(fileDest), False);
sShowMessage('Backup Successfull','Backup was completed successfully. File saved to'+#13+#10' '+filedest+'.') ;
sShowMessage('Backup Aborted','Backup cancelled at users request');