VB Script Help- Submitting to Access DB

tark221

New Member
Joined
Apr 11, 2013
Messages
19
Hi All,

I have a HTA file which when the submit button is clicked it runs the below VB script. No matter what I have tried It doesn't like "CUser=objNetwork.UserName". When I change the SQL code to not include the username variable it works fine but I need to capture the current user. Any help would be much appreciated.

Code:
<!--VBA SCRIPT-->******** language="VBScript">
Sub Window_******
window.resizeTo 900,430
Comments_Area.value="Please enter comments here..."
End Sub 


Sub Confirmation
Dim sConnect
Dim objCmd
Dim objRS
Dim objNetwork


Set objNetwork = CreateObject("Wscript.Network")
CUser=objNetwork.UserName


Set Question_1 = document.getElementById("Q1")
Set Question_2 = document.getElementById("Q2")
Set Question_3 = document.getElementById("Q3")
Set Question_4 = document.getElementById("Q4")
Set Question_5 = document.getElementById("Q5")


sConnect = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=C:\Users\testa\Desktop\DB_TFT.accdb;Persist Security Info=False"


Set objCmd = CreateObject("ADODB.Command")
objCmd.ActiveConnection = sConnect
objCmd.CommandText = "INSERT INTO TBL_FEEDBACK(Q1,Q2,Q3,Q4,Q5,COMMENTS,CURRENT_USER,DATE_SUBMITTED) VALUES(" & Question_1.VALUE & "," & Question_2.VALUE & "," & Question_3.VALUE & "," & Question_4.VALUE & "," & Question_5.VALUE & ",'" & Comments_Area.value &"','" & CUser &"',#" & Date() &"#);"


Set objRS = CreateObject("ADODB.Recordset")
Set objRS = objCmd.Execute
End Sub
*********>
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,216,081
Messages
6,128,694
Members
449,464
Latest member
againofsoul

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top