(“WScript.Network”).UserName in not being Saved in Access
I used the following VBA Code in The Form (General)
Public Function GetUserName() As String
GetUserName = CreateObject("WScript.Network").UserName
End Function
The Control source = User_Name
Default Value = GetUserName()
The Problem -
The username is correctly Pulled in the form, however it is not being saved in the Control Source i.e in the Table. Even after I save and close the form.
I need the form to capture and save the Username every time someone makes changes to a record.
Please Help I am new to MS Access
vba ms-access access-vba
|
show 1 more comment
I used the following VBA Code in The Form (General)
Public Function GetUserName() As String
GetUserName = CreateObject("WScript.Network").UserName
End Function
The Control source = User_Name
Default Value = GetUserName()
The Problem -
The username is correctly Pulled in the form, however it is not being saved in the Control Source i.e in the Table. Even after I save and close the form.
I need the form to capture and save the Username every time someone makes changes to a record.
Please Help I am new to MS Access
vba ms-access access-vba
1
There's anEnviron$
function you can use to get the Windows login username, doesEnviron$("USERNAME")
not return the correct value? In any case, that's just a function that gets a string, it's not saving anything anywhere. Who's calling that code? Please edit your post to include the code that's relevant to the problem.
– Mathieu Guindon
Nov 26 '18 at 22:32
The code is relevant to the problem. According to many user comments Environ("USERNAME") is easily spoofed and hence the approach to use WScript.Network object. is used. The issue is that I am not able to capture it in the table every time some one logs in.
– Ankita Zaveri
Nov 26 '18 at 22:36
1
lol, this is VBA. Ctrl+Break and anyone can spoof anything.
– Mathieu Guindon
Nov 26 '18 at 22:40
1
I tested to your code and it works. However, DefaultValue only executes on new record creation, not on record edits. If you want to change the value then will need code to do that.
– June7
Nov 26 '18 at 22:41
I use the following code so the form opens at a new record DoCmd.GoToRecord , , acNewRec - Still it does not save the value. I kind of understand what you are saving. Let me explain me a a bit clearly - On opening the application the application opens at welcome Log in page which pulls the Default time, Date and User name to Track who opens and edits the Application
– Ankita Zaveri
Nov 26 '18 at 22:43
|
show 1 more comment
I used the following VBA Code in The Form (General)
Public Function GetUserName() As String
GetUserName = CreateObject("WScript.Network").UserName
End Function
The Control source = User_Name
Default Value = GetUserName()
The Problem -
The username is correctly Pulled in the form, however it is not being saved in the Control Source i.e in the Table. Even after I save and close the form.
I need the form to capture and save the Username every time someone makes changes to a record.
Please Help I am new to MS Access
vba ms-access access-vba
I used the following VBA Code in The Form (General)
Public Function GetUserName() As String
GetUserName = CreateObject("WScript.Network").UserName
End Function
The Control source = User_Name
Default Value = GetUserName()
The Problem -
The username is correctly Pulled in the form, however it is not being saved in the Control Source i.e in the Table. Even after I save and close the form.
I need the form to capture and save the Username every time someone makes changes to a record.
Please Help I am new to MS Access
vba ms-access access-vba
vba ms-access access-vba
edited Nov 26 '18 at 22:45
June7
4,54351126
4,54351126
asked Nov 26 '18 at 22:20
Ankita ZaveriAnkita Zaveri
385
385
1
There's anEnviron$
function you can use to get the Windows login username, doesEnviron$("USERNAME")
not return the correct value? In any case, that's just a function that gets a string, it's not saving anything anywhere. Who's calling that code? Please edit your post to include the code that's relevant to the problem.
– Mathieu Guindon
Nov 26 '18 at 22:32
The code is relevant to the problem. According to many user comments Environ("USERNAME") is easily spoofed and hence the approach to use WScript.Network object. is used. The issue is that I am not able to capture it in the table every time some one logs in.
– Ankita Zaveri
Nov 26 '18 at 22:36
1
lol, this is VBA. Ctrl+Break and anyone can spoof anything.
– Mathieu Guindon
Nov 26 '18 at 22:40
1
I tested to your code and it works. However, DefaultValue only executes on new record creation, not on record edits. If you want to change the value then will need code to do that.
– June7
Nov 26 '18 at 22:41
I use the following code so the form opens at a new record DoCmd.GoToRecord , , acNewRec - Still it does not save the value. I kind of understand what you are saving. Let me explain me a a bit clearly - On opening the application the application opens at welcome Log in page which pulls the Default time, Date and User name to Track who opens and edits the Application
– Ankita Zaveri
Nov 26 '18 at 22:43
|
show 1 more comment
1
There's anEnviron$
function you can use to get the Windows login username, doesEnviron$("USERNAME")
not return the correct value? In any case, that's just a function that gets a string, it's not saving anything anywhere. Who's calling that code? Please edit your post to include the code that's relevant to the problem.
– Mathieu Guindon
Nov 26 '18 at 22:32
The code is relevant to the problem. According to many user comments Environ("USERNAME") is easily spoofed and hence the approach to use WScript.Network object. is used. The issue is that I am not able to capture it in the table every time some one logs in.
– Ankita Zaveri
Nov 26 '18 at 22:36
1
lol, this is VBA. Ctrl+Break and anyone can spoof anything.
– Mathieu Guindon
Nov 26 '18 at 22:40
1
I tested to your code and it works. However, DefaultValue only executes on new record creation, not on record edits. If you want to change the value then will need code to do that.
– June7
Nov 26 '18 at 22:41
I use the following code so the form opens at a new record DoCmd.GoToRecord , , acNewRec - Still it does not save the value. I kind of understand what you are saving. Let me explain me a a bit clearly - On opening the application the application opens at welcome Log in page which pulls the Default time, Date and User name to Track who opens and edits the Application
– Ankita Zaveri
Nov 26 '18 at 22:43
1
1
There's an
Environ$
function you can use to get the Windows login username, does Environ$("USERNAME")
not return the correct value? In any case, that's just a function that gets a string, it's not saving anything anywhere. Who's calling that code? Please edit your post to include the code that's relevant to the problem.– Mathieu Guindon
Nov 26 '18 at 22:32
There's an
Environ$
function you can use to get the Windows login username, does Environ$("USERNAME")
not return the correct value? In any case, that's just a function that gets a string, it's not saving anything anywhere. Who's calling that code? Please edit your post to include the code that's relevant to the problem.– Mathieu Guindon
Nov 26 '18 at 22:32
The code is relevant to the problem. According to many user comments Environ("USERNAME") is easily spoofed and hence the approach to use WScript.Network object. is used. The issue is that I am not able to capture it in the table every time some one logs in.
– Ankita Zaveri
Nov 26 '18 at 22:36
The code is relevant to the problem. According to many user comments Environ("USERNAME") is easily spoofed and hence the approach to use WScript.Network object. is used. The issue is that I am not able to capture it in the table every time some one logs in.
– Ankita Zaveri
Nov 26 '18 at 22:36
1
1
lol, this is VBA. Ctrl+Break and anyone can spoof anything.
– Mathieu Guindon
Nov 26 '18 at 22:40
lol, this is VBA. Ctrl+Break and anyone can spoof anything.
– Mathieu Guindon
Nov 26 '18 at 22:40
1
1
I tested to your code and it works. However, DefaultValue only executes on new record creation, not on record edits. If you want to change the value then will need code to do that.
– June7
Nov 26 '18 at 22:41
I tested to your code and it works. However, DefaultValue only executes on new record creation, not on record edits. If you want to change the value then will need code to do that.
– June7
Nov 26 '18 at 22:41
I use the following code so the form opens at a new record DoCmd.GoToRecord , , acNewRec - Still it does not save the value. I kind of understand what you are saving. Let me explain me a a bit clearly - On opening the application the application opens at welcome Log in page which pulls the Default time, Date and User name to Track who opens and edits the Application
– Ankita Zaveri
Nov 26 '18 at 22:43
I use the following code so the form opens at a new record DoCmd.GoToRecord , , acNewRec - Still it does not save the value. I kind of understand what you are saving. Let me explain me a a bit clearly - On opening the application the application opens at welcome Log in page which pulls the Default time, Date and User name to Track who opens and edits the Application
– Ankita Zaveri
Nov 26 '18 at 22:43
|
show 1 more comment
1 Answer
1
active
oldest
votes
It looks like you are assigning the user name to the control source. Access does not work like this. The control source is supposed to contain a column name.
Create a table having columns you can use to store things. Then set the form's Record Source property to this table name at design time in the properties window. Then set the Control Source
of a text box to the column name where you want to store data or add objects to the form using the fields list.
Iin the form load event you can assign a user name to this textbox with
me!theTextBoxName = GetUserName()
You can also do this with an unbound textbox, but this name will not be stored when you close the form.
But as @June7 points out, you have probably done this already. In this case you should open the form with
DoCmd.OpenForm "theFormName", DataMode:=acFormAdd
... to create a new record.
1
I think OP has already done that. The question shows that the ControlSource is bound to field named User_Name.
– June7
Nov 26 '18 at 22:43
Yes I am using Existing Table Field User_Name to store the values. I will try the Form load Method to see if it can store. Thank you
– Ankita Zaveri
Nov 26 '18 at 22:49
in the form load event, assigning a user name to this textbox with me!theTextBoxName = GetUserName() - Worked well instead of Assigning it to default value. Thank you Everyone
– Ankita Zaveri
Nov 26 '18 at 22:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53490003%2fwscript-network-username-in-not-being-saved-in-access%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It looks like you are assigning the user name to the control source. Access does not work like this. The control source is supposed to contain a column name.
Create a table having columns you can use to store things. Then set the form's Record Source property to this table name at design time in the properties window. Then set the Control Source
of a text box to the column name where you want to store data or add objects to the form using the fields list.
Iin the form load event you can assign a user name to this textbox with
me!theTextBoxName = GetUserName()
You can also do this with an unbound textbox, but this name will not be stored when you close the form.
But as @June7 points out, you have probably done this already. In this case you should open the form with
DoCmd.OpenForm "theFormName", DataMode:=acFormAdd
... to create a new record.
1
I think OP has already done that. The question shows that the ControlSource is bound to field named User_Name.
– June7
Nov 26 '18 at 22:43
Yes I am using Existing Table Field User_Name to store the values. I will try the Form load Method to see if it can store. Thank you
– Ankita Zaveri
Nov 26 '18 at 22:49
in the form load event, assigning a user name to this textbox with me!theTextBoxName = GetUserName() - Worked well instead of Assigning it to default value. Thank you Everyone
– Ankita Zaveri
Nov 26 '18 at 22:53
add a comment |
It looks like you are assigning the user name to the control source. Access does not work like this. The control source is supposed to contain a column name.
Create a table having columns you can use to store things. Then set the form's Record Source property to this table name at design time in the properties window. Then set the Control Source
of a text box to the column name where you want to store data or add objects to the form using the fields list.
Iin the form load event you can assign a user name to this textbox with
me!theTextBoxName = GetUserName()
You can also do this with an unbound textbox, but this name will not be stored when you close the form.
But as @June7 points out, you have probably done this already. In this case you should open the form with
DoCmd.OpenForm "theFormName", DataMode:=acFormAdd
... to create a new record.
1
I think OP has already done that. The question shows that the ControlSource is bound to field named User_Name.
– June7
Nov 26 '18 at 22:43
Yes I am using Existing Table Field User_Name to store the values. I will try the Form load Method to see if it can store. Thank you
– Ankita Zaveri
Nov 26 '18 at 22:49
in the form load event, assigning a user name to this textbox with me!theTextBoxName = GetUserName() - Worked well instead of Assigning it to default value. Thank you Everyone
– Ankita Zaveri
Nov 26 '18 at 22:53
add a comment |
It looks like you are assigning the user name to the control source. Access does not work like this. The control source is supposed to contain a column name.
Create a table having columns you can use to store things. Then set the form's Record Source property to this table name at design time in the properties window. Then set the Control Source
of a text box to the column name where you want to store data or add objects to the form using the fields list.
Iin the form load event you can assign a user name to this textbox with
me!theTextBoxName = GetUserName()
You can also do this with an unbound textbox, but this name will not be stored when you close the form.
But as @June7 points out, you have probably done this already. In this case you should open the form with
DoCmd.OpenForm "theFormName", DataMode:=acFormAdd
... to create a new record.
It looks like you are assigning the user name to the control source. Access does not work like this. The control source is supposed to contain a column name.
Create a table having columns you can use to store things. Then set the form's Record Source property to this table name at design time in the properties window. Then set the Control Source
of a text box to the column name where you want to store data or add objects to the form using the fields list.
Iin the form load event you can assign a user name to this textbox with
me!theTextBoxName = GetUserName()
You can also do this with an unbound textbox, but this name will not be stored when you close the form.
But as @June7 points out, you have probably done this already. In this case you should open the form with
DoCmd.OpenForm "theFormName", DataMode:=acFormAdd
... to create a new record.
edited Nov 26 '18 at 22:49
answered Nov 26 '18 at 22:39
Olivier Jacot-DescombesOlivier Jacot-Descombes
68k888140
68k888140
1
I think OP has already done that. The question shows that the ControlSource is bound to field named User_Name.
– June7
Nov 26 '18 at 22:43
Yes I am using Existing Table Field User_Name to store the values. I will try the Form load Method to see if it can store. Thank you
– Ankita Zaveri
Nov 26 '18 at 22:49
in the form load event, assigning a user name to this textbox with me!theTextBoxName = GetUserName() - Worked well instead of Assigning it to default value. Thank you Everyone
– Ankita Zaveri
Nov 26 '18 at 22:53
add a comment |
1
I think OP has already done that. The question shows that the ControlSource is bound to field named User_Name.
– June7
Nov 26 '18 at 22:43
Yes I am using Existing Table Field User_Name to store the values. I will try the Form load Method to see if it can store. Thank you
– Ankita Zaveri
Nov 26 '18 at 22:49
in the form load event, assigning a user name to this textbox with me!theTextBoxName = GetUserName() - Worked well instead of Assigning it to default value. Thank you Everyone
– Ankita Zaveri
Nov 26 '18 at 22:53
1
1
I think OP has already done that. The question shows that the ControlSource is bound to field named User_Name.
– June7
Nov 26 '18 at 22:43
I think OP has already done that. The question shows that the ControlSource is bound to field named User_Name.
– June7
Nov 26 '18 at 22:43
Yes I am using Existing Table Field User_Name to store the values. I will try the Form load Method to see if it can store. Thank you
– Ankita Zaveri
Nov 26 '18 at 22:49
Yes I am using Existing Table Field User_Name to store the values. I will try the Form load Method to see if it can store. Thank you
– Ankita Zaveri
Nov 26 '18 at 22:49
in the form load event, assigning a user name to this textbox with me!theTextBoxName = GetUserName() - Worked well instead of Assigning it to default value. Thank you Everyone
– Ankita Zaveri
Nov 26 '18 at 22:53
in the form load event, assigning a user name to this textbox with me!theTextBoxName = GetUserName() - Worked well instead of Assigning it to default value. Thank you Everyone
– Ankita Zaveri
Nov 26 '18 at 22:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53490003%2fwscript-network-username-in-not-being-saved-in-access%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
There's an
Environ$
function you can use to get the Windows login username, doesEnviron$("USERNAME")
not return the correct value? In any case, that's just a function that gets a string, it's not saving anything anywhere. Who's calling that code? Please edit your post to include the code that's relevant to the problem.– Mathieu Guindon
Nov 26 '18 at 22:32
The code is relevant to the problem. According to many user comments Environ("USERNAME") is easily spoofed and hence the approach to use WScript.Network object. is used. The issue is that I am not able to capture it in the table every time some one logs in.
– Ankita Zaveri
Nov 26 '18 at 22:36
1
lol, this is VBA. Ctrl+Break and anyone can spoof anything.
– Mathieu Guindon
Nov 26 '18 at 22:40
1
I tested to your code and it works. However, DefaultValue only executes on new record creation, not on record edits. If you want to change the value then will need code to do that.
– June7
Nov 26 '18 at 22:41
I use the following code so the form opens at a new record DoCmd.GoToRecord , , acNewRec - Still it does not save the value. I kind of understand what you are saving. Let me explain me a a bit clearly - On opening the application the application opens at welcome Log in page which pulls the Default time, Date and User name to Track who opens and edits the Application
– Ankita Zaveri
Nov 26 '18 at 22:43