Connecting Tech Pros Worldwide Help | Site Map

windows username to ms access

  #1  
Old September 23rd, 2008, 02:41 PM
Newbie
 
Join Date: Aug 2008
Posts: 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

Last edited by acoder; September 23rd, 2008 at 04:17 PM. Reason: Added [code] tags
  #2  
Old September 23rd, 2008, 07:57 PM
Expert
 
Join Date: Nov 2006
Posts: 392

re: windows username to ms access


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.
  #3  
Old September 25th, 2008, 05:58 PM
Newbie
 
Join Date: Aug 2008
Posts: 28

re: windows username to ms access


security would not be a concern, the only problem i see is in line 27.....
  #4  
Old September 25th, 2008, 08:07 PM
Expert
 
Join Date: Nov 2006
Posts: 392

re: windows username to ms access


Quote:
Originally Posted by orajat
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.



Quote:
Originally Posted by orajat
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?

Last edited by pronerd; September 25th, 2008 at 08:13 PM. Reason: Add more details
  #5  
Old September 26th, 2008, 06:54 PM
Newbie
 
Join Date: Aug 2008
Posts: 28

re: windows username to ms access


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

xx

Quote:
Originally Posted by pronerd
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?
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Access Macro Scheduling rajatsingh78 answers 5 August 28th, 2007 05:54 PM
DAO access error w.Ms Access Ben answers 6 November 21st, 2005 07:56 PM
Can't insert data to MS Access 2003 dale zhang answers 5 November 17th, 2005 07:35 AM
Limit of users in Ms-Access? Hannu answers 6 November 13th, 2005 03:48 AM