By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,848 Members | 3,203 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,848 IT Pros & Developers. It's quick & easy.

windows username to ms access

P: 28
hi,

I'm trying to pull the windows username with jscript and save it to ms access field in a table, but it does not work. it does show the alert with the name of the user but does not save it to the ms access field. here i steh code that i'm using. please help

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT type=text/javascript>
  2. <!--
  3. var WinNetwork = new ActiveXObject("WScript.Network");  
  4. alert(WinNetwork.userName);
  5.  
  6. var adOpenDynamic = 2;
  7. var adLockOptimistic = 3;
  8.  
  9. /* Path of database.
  10. */
  11. var strDbPath = "C:\Documents and Settings\ASPIRE\Desktop\ss1 upgrade\SS1\db1";
  12.  
  13. /*
  14. Here is the ConnectionString for Microsoft Access.
  15.  
  16. */
  17. var conn_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strDbPath;
  18.  
  19. function AddRecord() {
  20. var adoConn = new ActiveXObject("ADODB.Connection");
  21. var adoRS = new ActiveXObject("ADODB.Recordset");
  22.  
  23. adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='\\db1.mdb'");
  24. adoRS.Open("Select * From TimeTrackerTable Where Group = 'xxxx'", adoConn, 1, 3);
  25.  
  26. adoRS.AddNew;
  27. adoRS.Fields("Group").value = "(WinNetwork.userName)";
  28. adoRS.Update;
  29.  
  30. adoRS.Close();
  31. adoConn.Close();
  32. }
  33.  
  34.  
  35. function getAdoDb(strAdoType){
  36. if (window.ActiveXObject){
  37. return new ActiveXObject(strAdoType);
  38. }
  39. else{
  40. return ActiveXObject(strAdoType);
  41. }
  42. }
  43. </SCRIPT>
  44.  <INPUT id=Button1 onclick=EditRecord() type=button name=Command0 ;><BR>
  45. <SCRIPT language=javascript event=onclick for=Command0>
  46. try { if (MSODSC.DataPages.Count > 0)
  47. if (MSODSC.CurrentSection == null)
  48.     MSODSC.DataPages(0).Save();
  49. else
  50.     MSODSC.CurrentSection.DataPage.Save(); }    
  51. catch (e)
  52. { alert (e.description);}
  53. </SCRIPT>
  54.  
Regards,
xx
Sep 23 '08 #1
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 392
This is really more of an ActiveX question than a JavaScript one so you may want to try a forum that covers that.

I do see a number of issues, but I do not know if any of them are the problem.

First off the alert is being called because it is in the catch block. Some exception is being thrown causing the field value to not be set and causing the code in the catch block to execute instead.

Secondly the attributes in your HTML tags need to be surrounded by quotes. Third there is a semicolon in your input tag that should not be there.

The tags should look like this:
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT type="text/javascript">
Expand|Select|Wrap|Line Numbers
  1. <INPUT id="Button1" onclick="EditRecord()" type="button" name="Command0" />
Fouth the line below has a number of problems. All the attribute values need quotes. I do not see "event" or "for" as valid attributes for the script tag in any DOM documentation. Even if they are in IE how would you ever have an onclick event on a script tag. It is not rendered on the page and can not be clicked on.
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language=javascript event=onclick for=Command0>
Last but not lest what you are trying to do is ex termly unsafe. I would be very surprised if IE will let you run this code by default even in the local zone. So you will probably have to lower your IE security setting all the way for this code to run.
Sep 23 '08 #2

P: 28
security would not be a concern, the only problem i see is in line 27.....
Sep 25 '08 #3

Expert 100+
P: 392
security would not be a concern,
It may not be a concern, but it is a problem. It is very unlikely that IE will let you do direct local system access in the default security settings. You will have to lower your security settings to the lowest point to be able to do local system access like this.



the only problem i see is in line 27.....
And you are basing that on what? Line 17 is not even inside the try catch block where the exception is being thrown. For that matter I do not even see where the function for the code on line 27 is called. What is calling the getAdoDb() function?
Sep 25 '08 #4

P: 28
by problem i meant that the whole excercise is to save the windows username in the ms access field, which is not hapenning....

xx

It may not be a concern, but it is a problem. It is very unlikely that IE will let you do direct local system access in the default security settings. You will have to lower your security settings to the lowest point to be able to do local system access like this.




And you are basing that on what? Line 17 is not even inside the try catch block where the exception is being thrown. For that matter I do not even see where the function for the code on line 27 is called. What is calling the getAdoDb() function?
Sep 26 '08 #5

Post your reply

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