Solved Unable to save form record (1 Viewer)

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:30
Joined
Feb 19, 2002
Messages
42,981
There are lots of much more complicated scripts out there but this one has worked for me for years. It doesn't raise an error in the MD if the directory already exists, nor does it raise an error in the del if the database doesn't exist because in both cases, I would ignore the error anyway. So my position is, don't raise an error you don't want to handle :)

Notice that the standard and Citrix .bat files are identical in how they work. They just reference the local directory differently.

Standard .bat file
Code:
md c:\DwgLog
del c:\DwgLog\DrawingLog.accdb
copy "\\BSCCTIMBERLINE1\Timberline Office\AccessApps\Data\CommonFE\DrawingLog.accdb" c:\DwgLog
c:\DwgLog\DrawingLog.accdb
Citrix .bat file
Code:
md %USERPROFILE%\DwgLog
del %USERPROFILE%\DwgLog\DrawingLog.accdb
copy "\\BSCCTIMBERLINE1\Timberline Office\AccessApps\Data\CommonFE\DrawingLog.accdb" %USERPROFILE%\DwgLog
%USERPROFILE%\DwgLog\DrawingLog.accdb
 

db-noob

Member
Local time
Yesterday, 18:30
Joined
Oct 16, 2020
Messages
47
There are lots of much more complicated scripts out there but this one has worked for me for years. It doesn't raise an error in the MD if the directory already exists, nor does it raise an error in the del if the database doesn't exist because in both cases, I would ignore the error anyway. So my position is, don't raise an error you don't want to handle :)

Notice that the standard and Citrix .bat files are identical in how they work. They just reference the local directory differently.

Standard .bat file
Code:
md c:\DwgLog
del c:\DwgLog\DrawingLog.accdb
copy "\\BSCCTIMBERLINE1\Timberline Office\AccessApps\Data\CommonFE\DrawingLog.accdb" c:\DwgLog
c:\DwgLog\DrawingLog.accdb
Citrix .bat file
Code:
md %USERPROFILE%\DwgLog
del %USERPROFILE%\DwgLog\DrawingLog.accdb
copy "\\BSCCTIMBERLINE1\Timberline Office\AccessApps\Data\CommonFE\DrawingLog.accdb" %USERPROFILE%\DwgLog
%USERPROFILE%\DwgLog\DrawingLog.accdb
I'm familiar with Linux commands (not all, but some), so I'm guessing this is done in a command line for a Windows machine? I've messed with batch files using console commands in Skyrim, but never anything else. But this is interesting! I don't have access to the other users' machines because I'm not their IT manager, but I could definitely make & edit copies for every user to include on their desktop.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:30
Joined
Feb 19, 2002
Messages
42,981
What I do is create the .bat file and leave it on the server. Then I send the users a shortcut that runs the .bat file and they can place the shortcut on their desktops. Placing the .bat file on the server makes it easy for you to change it if you need to. If you send it to each user, you would need to somehow update it on each user PC if you needed to change it.
 

db-noob

Member
Local time
Yesterday, 18:30
Joined
Oct 16, 2020
Messages
47
What I do is create the .bat file and leave it on the server. Then I send the users a shortcut that runs the .bat file and they can place the shortcut on their desktops. Placing the .bat file on the server makes it easy for you to change it if you need to. If you send it to each user, you would need to somehow update it on each user PC if you needed to change it.
Cool! Two questions.
1) Do I have to make a new directory? I figure mine would be:
Code:
del C:\Users\<User>\Desktop\database.accdb
copy "\\<ServerName>\...Path...\frontend.accdb" C:\Users\<User>\Desktop\
2) Why is "c:\DwgLog\DrawingLog.accdb" on the last line? Since you already have "c:\DwgLog" on the copy line.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:30
Joined
Feb 19, 2002
Messages
42,981
I don't like to save files to the desktop because I believe that the user should decide what should be on his desktop. Also, this method needs to run from a shortcut because you ALWAYS want the user to download a new version of the app each time he opens it. The shortcut should be on the desktop so having both the shortcut and the actual .accdb on the desktop will certainly lead to confusion and mis-use of the app. So, do NOT save the database to the desktop. If you want to save it to a different existing folder, that would be fine.

The last line opens the application.


From your questions, I think you are misunderstanding the purpose of using a batch file. If the user opens the database directly (even if it is his own personal copy), you would need to have code in the app that runs whenever the app opens to determine if the file that was opened is the most recent version. As I said earlier, this gets more complicated. You can do it but since you can't replace a file that is open, you need a trick and the trick is opening a different database that closes the original, deletes it, and downloads a new one. You can certainly write all that code but I gave you a batch file that is only four lines of code. OK, you don't want to make a directory, fine. Now you need three lines of code but the .accdb is lost in a sea of perhaps thousands of files if you use a system folder.
 

db-noob

Member
Local time
Yesterday, 18:30
Joined
Oct 16, 2020
Messages
47
I don't like to save files to the desktop because I believe that the user should decide what should be on his desktop. Also, this method needs to run from a shortcut because you ALWAYS want the user to download a new version of the app each time he opens it. The shortcut should be on the desktop so having both the shortcut and the actual .accdb on the desktop will certainly lead to confusion and mis-use of the app. So, do NOT save the database to the desktop. If you want to save it to a different existing folder, that would be fine.

The last line opens the application.


From your questions, I think you are misunderstanding the purpose of using a batch file. If the user opens the database directly (even if it is his own personal copy), you would need to have code in the app that runs whenever the app opens to determine if the file that was opened is the most recent version. As I said earlier, this gets more complicated. You can do it but since you can't replace a file that is open, you need a trick and the trick is opening a different database that closes the original, deletes it, and downloads a new one. You can certainly write all that code but I gave you a batch file that is only four lines of code. OK, you don't want to make a directory, fine. Now you need three lines of code but the .accdb is lost in a sea of perhaps thousands of files if you use a system folder.
Unfortunately, you are correct. How I used batch files in Skyrim and how they work eludes me. All I ever do is type "bat <filename>" in the console and it does what I coded it to do. 😫

Okay. So I'll have to delete the FE's that are their desktops and give them a shortcut on their desktop, for example:

Code:
md C:\Access
del C:\Access\database.accdb
copy "<filepath to FE" C:\Access
C:\Access\database.accdb

Am I getting close?
 

db-noob

Member
Local time
Yesterday, 18:30
Joined
Oct 16, 2020
Messages
47
Created a batch file on the server and sent it as a shortcut to my desktop to test it out. I had to change a few things:
Code:
md C:\Access
del "C:\Access\SERCOM Database_FrontEnd.accdb"
copy "\\<path>\SERCOM Database_FrontEnd.accdb" C:\Access
start msaccess "C:\Access\SERCOM Database_FrontEnd.accdb"

The "start msaccess" bit is redundant, but it slightly reminds me of opening a program in Linux so I'll take that comfort. But it seems to work! Will see how it goes.

Thanks @Pat Hartman and sorry for the trouble!
 

Users who are viewing this thread

Top Bottom