How to hold the value of a prompted password in a variable while file is open?
I have this little VBA macro that uses ADODB to execute a SQL Server Agent job remotely. It is in an Excel file, and there will be several other similar macros in the same Excel file. They will be used at least 10 times, each time the user opens
the Excel file. If I leave it like this, the user will be prompted for the password every single time they run one of the macros. How can I change it to instead prompt the user for the password value initially when they open the file, store it
in a variable, and then utilize that variable value for the database connection every time they run one of the macros (to avoid repeated prompting)? Also, are there any security concerns with my proposed approach?
Sub Test_SSIS()
Dim conn As Object
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "sqloledb"
conn.Properties("Prompt") = adPromptComplete
conn.Open = "Data Source=MYSERVER;USER ID=JOHNDOE;"
conn.Execute "exec msdb.dbo.sp_start_job 'Test_remote_job_execution'"
End Sub
One possibility is to use the workbook_open event to prompt for and store the password temporarily in the registry. Add the following code to the thisworkbook module of the workbook
Option Explicit
Private Sub Workbook_Open()
Dim strPassword As String
strPassword = GetSetting("myApp", "Config", "Password", "")
If strPassword = "" Then
strPassword = InputBox("Enter password")
SaveSetting "myApp", "Config", "Password", strPassword
End If
lbl_Exit:
Exit Sub
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
RegKeyDelete "HKEY_CURRENT_USER\Software\VB and VBA Program Settings\myApp\Config\"
If RegKeyDelete("HKEY_CURRENT_USER\Software\VB and VBA Program Settings\myApp\") = True Then
MsgBox "Password cleared"
Else
MsgBox "Password not stored"
End If
lbl_Exit:
Exit Sub
End Sub
Function RegKeyDelete(i_RegKey As String) As Boolean
Dim myWS As Object
On Error GoTo ErrorHandler
Set myWS = CreateObject("WScript.Shell")
myWS.RegDelete i_RegKey
RegKeyDelete = True
Exit Function
lbl_Exit:
Exit Function
ErrorHandler:
RegKeyDelete = False
GoTo lbl_Exit
End Function
Then modify your macro code as follows:
Sub Test_SSIS()
Dim strPassword As String
Dim conn As Object
strPassword = GetSetting("myApp", "Config", "Password", "")
If strPassword = "" Then
strPassword = InputBox("Enter password")
SaveSetting "myApp", "Config", "Password", strPassword
End If
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "sqloledb"
conn.Open "DATA SOURCE=MYSERVER;USER ID=JOHNDOE;Password=" & strPassword & ";"
conn.Execute "exec msdb.dbo.sp_start_job 'Test_remote_job_execution'"
End Sub
The workbook must obviously be saved as macro enabled
This will then prompt once when the workbook is opened. When the macro is run it will read the password from the registry thus not requiring a prompt, unless for some reason the password is missing or nothing has been entered as a value in the first box.
When the workbook is closed, the workbook before close event deletes the registry entries completely.
The only snag to this is if the workbook is crashed, the registry entry is not removed and there will be no prompt next time, until the workbook is closed correc tly. This might not be an issue, if the users don't know about it, so hide your code from them.
Graham Mayor - Word MVP
www.gmayor.com
Similar Messages
-
How to hold the value in List box.
Hi All,
On my screen painter Screen I am displaying the Sold to party and ship to party with thier address.
I am also displaying the Shipping condition based on ship to party. To display the shipping condition i am using list box. Once the user enter the sold to party automatically all the field is going to populate in their respective fields. I am facing the problem that, The list box getting populated with shipping condition but once you choose the shipping condition and hit the enter the list box getting refreshed. I am using this code in PAI event. And I can Only use this in PAI.
The Function i am using for list box is CALL FUNCTION 'VRM_SET_VALUES'.
Pls suggest me how to hold the value in List box.
Thanks,
RakeshHi,
Now i am using in PBO.
the code below in in PBO.It is still not holding the value.
if list[] is initial.
perform SHP_COND.
endif.
form SHP_COND .
*DATA: SHOP(80).
clear : GT_VSBED, list.
refresh : GT_VSBED, list.
select vsbed
from knvv AS K
into table GT_VSBED
where Kvkorg = vbak-vkorg "Kkunnr = GV_STPH
and K~vtweg = vbak-vtweg
and K~spart = vbak-spart.
select VSBED vtext
from TVSBT
into table list
for all entries in GT_VSBED
where spras = sy-langu
and vsbed = GT_VSBED-VSBED.
*break-point.
NAME = 'SHP_CON'.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = NAME
values = LIST[]
EXCEPTIONS
ID_ILLEGAL_NAME = 1
OTHERS = 2
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endform. " SHP_COND
Thanks,
Rakesh -
How to hold the values as it's not holding the values when it cross 255
DATA : fval1 TYPE edidd-sdata.
DATA : fval2 TYPE edidd-sdata.
DATA : fval3 TYPE edidd-sdata.
DATA : fval4 TYPE edidd-sdata.
DATA : fval5 TYPE edidd-sdata.
DATA : len(3) TYPE n.
values1 = wa_final-low.
values2 = wa_final-high.
IF wa_final-high IS NOT INITIAL.
CONCATENATE values1 values2 INTO fval1 SEPARATED BY '-'.
ELSE.
fval2 = values1.
ENDIF.
IF fval3 IS NOT INITIAL.
IF fval1 IS NOT INITIAL.
fval = fval1.
CONCATENATE fval3 fval INTO fval3 SEPARATED BY '/'.
ENDIF.
IF fval2 IS NOT INITIAL.
fval = fval2.
CONCATENATE fval3 fval INTO fval3 SEPARATED BY '/'.
ENDIF.
ELSE.
IF fval1 IS NOT INITIAL.
fval3 = fval1.
ENDIF.
IF fval2 IS NOT INITIAL.
fval3 = fval2.
ENDIF.
ENDIF.
DATA : len(3) TYPE n.
len = STRLEN( fval3 ).
IF len > 250.
fval4 = fval3+0(250).
fval3 = fval3+250(5).
* CONCATENATE fval4 fval3 INTO fval5.
ENDIF.
IF fval4 IS INITIAL.
wa_final1-varbl31 = fval3.
ELSE.
CONCATENATE fval4 fval3 INTO fval5.
wa_final1-varbl31 = fval5.
ENDIF.
MODIFY it_final1 FROM wa_final1
TRANSPORTING varbl31 WHERE agr_name = wa_final-agr_name.
at this point also it's not holding the values when it exseds 255
kindly please helpH friends ,
i am not the expert at the same time i know some thing in abap
fval4 = fval3+0(250).
fval3 = fval3+250(5).
in the above case fval3 have 255 char at that time iam transporting 250 char to fval4 with this statment
fval4 = fval3+0(250).
and iam keeping the remaining 5 char in fval3 with this statment
fval3 = fval3+250(5)
so that i can push some more values in fval3 and at i am
CONCATENATE fval4 fval3 INTO fval5.
so that fval5 may get all values this is the way i try but fval5 is not holding all the values
i asked solution for that
fval 3 = fval3+250(250)
dosen't have any meaning i know that friend
my question is how to hold the remaining value -
How to capt the Value of Session Id [jsessionid] in a variable in e-tester
Hi,
We are facing a problem in the following scenario in e-testeer.
1. We had recorded two individual scripts in e-tester
a. Login Script of our application [ only login ] and
b. An Action Script which is DEPENDENT on the first script
We need to merge these two scipts in such a way, user would login through 1st script and then perform the action in 2nd script.
But there exists a dependency over session id on these actions.
Session ID generated in the first script needs to be used in the second script.
So the crux is we would like to know how to capture the session id generated in the LOGIN script and use it in the ACTION script in e-tester
Please provide a solution for our problem.
Thanks.
Edited by: user11144652 on May 8, 2009 2:10 AMHi All,
I found the solution for the above problem!!!
I used the 'GetCookies' and 'SetCookies' method of VBA for getting and setting the 'SessionID' across the scripts.
Examples for 'GetCookies' and 'SetCookies' methods are available in etester help itself.
We need to get the value of cookie from login script and need to store the value in a variable defined in a 'Shared Module'. Variable value stored in 'SharedModule' can be accessed across the scripts.
Thanks a lot for your time. -
We have a GUI swing screen in which we have navigation buttons.
when the user clicks the previous ,next, last,first buttons we have to show the records accordingly.
The min. size of the database is around 1 million.and each row has 60 columns.
Our approach is screen--->servlet-->ejb beans --->database.
since the database is huge how to hold the values, and where, without affecting the performance.
If we get the resultset it holds all the data.since the data size is huge,we are looking for a solution.The user may browse through the data ,edit the data and delete the data.
we have to perform accordingly. Also, if, for example, user1 is seeing record no.1 & user 2 has modified record no.3 in the meanwhile, when user1 goes to record no.3, he should see the
modified record. In short, the user should always see the latest values.
please give us the best approach to solve this problem.
Also this is in a multi user environment.It seems like you need to look at threads to update current values in the display and narrow the result set that you retrieve to match the criteria needed for display. You might consider making the method to change values a syncronized one.
-
How to store the value of sum of group in Crystal Report at the runtime!
Hello all,
I creates a Formula Field that hold the value of Sum of Group in Crystal Report. I would like to know how to store it in a variable and pass it to store procedure. Is it an option in Crystal report to do it. I knew that Crystal Report can cache the report for sharing. My detailed issue as following:
- Created a Formula Field named TOTAL AMOUNT that calculated the complex expression. This TOTAL AMOUNT is dynamic based on group and variables.
- I would like to store that value from TOTAL AMOUNT and pass it to the stored procedure parameter IN.
Any helps are much appreciated. Thanks.I doubt that this is possible since it would only calculate this value once the report has data. This sounds more like a report design question that should be asked over [here|SAP Crystal Reports;
-
Using a session object to hold the value of a record set?
Hi,
I'm trying to hold the value of a record set (or literally the content of a column in a query in a db) in a session variable so that I can call on this later and insert into another table.
I'm not sure of the correct syntax, I've already made a connection to the DB. I'm trying the following but it doesnt seem to like the code:
<% session.setAttribute("code",rs("column_name")); %>
<%String attrib =
String.valueOf ( session.getAttribute("code")); %>
Hello <%= attrib %>
Any ideas, I dont know how to reference the record set, I declared the recordset previously as rs. Help! Can't find examples anywhere on the net!So just to recap. I appear to be seeing the column name "custorderno" within the Microsoft Access query "lastcust". But I get "no data found" when I run the following code (which I have sectioned off)
<!-- connect to database and lastcust query --!>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/Tomcat/jakarta-tomcat-4.1.31/webapps/ROOT/Oatcake.mdb","","");
Statement statement = conn.createStatement();
String sql = "SELECT * FROM lastcust";
ResultSet rs = statement.executeQuery(sql);
while (rs.next()) {
%>
<TR><TD><%= rs.getString("custorderno") %></TD>
</TR>
<% session.setAttribute("code",rs.getString("custorderno")); %>
<% String attrib =
String.valueOf ( session.getAttribute("code") ); %>
Hello <%= attrib %> [B]
<%
%>
</TABLE>
<%
if (statement != null)
statement.close();
if (conn != null)
conn.close();
catch (Exception e) {out.print(e);}
%>
</BODY>
</HTML>
No as mentioned I am (as you can see) declaring everything as a string when in actual fact the contents of the "custorderno" within the query is set to a autonumber within MS Access.
The while loop does work by returning the contents but the session object part is not working correctly with the following result returned:
[B]java.sql.SQLException: No Data Found
Help please! -
How to determine the value of -D__SUNPRO_CC?
Could any body tell me how to determine the value of -D__SUNPRO_CC? Iam now using Sun Studio 9.
Thanks in advance.The C++ Users Guide describes all the predefined macros set by the compiler.
The __SUNPRO_CC macro is a 3-digit hex number. The first digit is the C++ compiler major version number, which is 5 for all releases from WorkShop 5 in 1998 through the current release, Sun Studio 10. The second digit is the minor version number, increasing by 1 for each release in the major release series. The 3rd digit is a place holder for the very rare (none since 1994) cases when we have a micro version number. It is zero in current releases.
The current compiler release is C++ 5.7, so __SUNPRO_CC is set to 0x570.
You can see the macro setting by running
CC -dryrun -c foo.cc
and look for the -D__SUNPRO_CC =0xNNN on the ccfe command line. -
How to get the values from popup window to mainwindow
HI all,
I want to get the details from popup window.
i have three input fields and one search button in my main window. when i click search button it should display popup window.whenever i click on selected row of the popup window table ,values should be visible in my main window input fields.(normal tables)
now i am able to display popup window with values.How to get the values from popup window now.
I can anybody explain me clearly.
Thanks&Regards
kranthiHi Kranthi,
Every webdynpro component has a global controller called the component controller which is visible to all other controllers within the component.So whenever you want to share some data in between 2 different views you can just make it a point to use the component controller's context for the same. For your requirement (within your popups view context) you will have have to copy the component controllers context to your view. You then will have to (programmatically) fill this context with your desired data in this popup view. You can then be able to read this context from whichever view you want. I hope that this would have made it clear for you. Am also giving you an [example|http://****************/Tutorials/WebDynproABAP/Modalbox/page1.htm] which you can go through which would give you a perfect understanding of all this. In this example the user has an input field in the main view. The user enters a customer number & presses on a pushbutton. The corresponding sales orders are then displayed in a popup window for the user. The user can then select any sales order & press on a button in the popup. These values would then get copied to the table in the main view.
Regards,
Uday -
To hold the value of a container in BPM
Hi,
How to access the value of the counter outside an infinite loop in the BPM, i have to use the counter calculated in the first infinite loop in the next while loop.
Let me know if any one has done this..
thankx,
ShreeYou mean inside the same BPM?
If that's so, you can use the local container you are using as counter wherever you want in the BPM. So, you can change the container in a step and use the same container (read its value) in any steps after that.
Regards,
Henrique. -
How to find the value of a variable in other program
How to find the value of a variable in other program say I am in a FM and this FM is being called in from other program and I want to know some of the variable details of the program from the FM itself. Imagine if this is a txn. and I need to know the details from some of the programs while executing the same transaction
Regards
VinHi Vinayak,
you will be having your first program values in internal table or some variables,
when you are calling the second program you wii use like this,
SUBMIT <Second Program Name> USING SELECTION-SCREEN '1000'
WITH s_emp(second program select-options) IN t_emp(first program variables)
WITH p_chk EQ t_chk
WITH p_r1 EQ t_r1
WITH p_month EQ t_month
WITH s_cust1 IN t_cust1
WITH p_r2 EQ t_r2
WITH s_cust2 IN t_cust2
WITH s_week IN t_week
AND RETURN.
you have pas like this to get your first program details. -
How to get the value from a JavaScript and send the same to Java file?
Hi.
How to get the value from a JavaScript (this JS is called when an action invoked) and send the value from the JS to a Java file?
Thanks and regards,
Leslie VYes, I am trying with web application.
In the below code, a variable 'message' carries the needed info. I would like to send this 'message' variable with the 'request'.
How to send this 'message' with and to the 'request'?
Thanks for the help :-)
The actual JS code is:
function productdeselection()
var i=0;
var j=0;
var deselectedproduct = new Array(5);
var message = "Are you sure to delete Product ";
mvi=document.forms[0].MVI;
mei=document.forms[0].MEI;
lpi=document.forms[0].LPI;
if(null != mvi)
++i;
if(null != mei )
++i;
if(null != lpi)
++i;
if(null != mvi && mvi.checked)
deselectedproduct[++j]="MVI?";
if(null != mei && mei.checked)
deselectedproduct[++j]="GAP?";
if(null != lpi && lpi.checked)
deselectedproduct[++j]="LPI?";
if( 0!=j)
if(i!=j)
for (x=0; x<deselectedproduct.length; x++)
if(null != deselectedproduct[x])
message =message+ "-" +deselectedproduct[x];
alert(message);
else
//alert(" You cannot remove all products!");
return false;
return true;
} -
How to get the value from databank
Hi,
How to get the value from databank? and how to set the same value to visual script object?
thanks,
raHi,
You can use GetDatabankValue(HeaderName, Value) to get the value from databank and SetDataBankValue(HeaderName, Value) to set the value to databank.
You can refer to the API Reference to see list of associated functions and techniques we can use with related to Data Bank.
This is the for OFT but if you are using Open Script then you have direct access for getting the databank value but when it comes to setting a value you have to use File operation and write you own methods to do the set operation.
Thanks
Edited by: Openscript User 100 on Nov 13, 2009 7:01 AM -
How to get the values from html:select? tag..?
i tried with this, but its not working...
<html:select styleClass="text" name="querydefs" property="shortcut"
onchange="retrieveOptions()" styleId="firstBox" indexed="true">
<html:options collection="advanced.choices" property="shortcut" labelProperty="label" />
</html:select>
<td align="left" class="rowcolor1">
<script language="javascript" type="text/javascript">
function retrieveOptions(){
var sel = document.querydefs.options;
var selectedOption = sel[sel.selectedIndex].value;
document.write(selectedOption);
</script><td align="left" class="rowcolor1">
<script language="javascript" type="text/javascript">
function retrieveOptions(){
var sel = document.querydefs.options;
var selectedOption = sel[sel.selectedIndex].value;
document.write(selectedOption);
</script>This java script is not working at all..its not printing anything in document.write();
This is code..
<td class="rowcolor1" width="20%">
<html:select styleClass="text" name="querydefs" property="shortcut"
onchange="retrieveSecondOptions()" styleId="firstBox"
indexed="true">
<html:options collection="advanced.choices" property="shortcut"
labelProperty="label" />
</html:select>i tried with this also. but no use..i'm not the getting the seleced option...
function retrieveOptions(){
firstBox = document.getElementById('firstBox');
if(firstBox.selectedIndex==0){
return;
selectedOption = firstBox.options[firstBox.selectedIndex].value;
}actually , how to get the values from <html:select> ...?
my idea is to know which value is selected from the combo box(<html:select> ) if that value is equal some string i have enable a hyperlink to open a popup window -
How to get the values from table region and how to set
Hi,
I have a requirement as Seeded Page Having One Table Region having around 8 columns, In That Item Description field is there. My Requirement is I need add one more field for that Region and assign the value depending Item Description.
I will create one new Item in that region and will give name as Item, But how to set the values to Item Depending on Item Description.
Is it possible to through CO Extension, If yes..Pls help how to get it.
Thanks in Advance,
HanimiHi Hanimi,
1. You need to extend the VO, add a new Attribute.
2. In VORowImpl of the extended VO, you can find the getter for your new attribute (example getItem())
3. In this getter method you can write some code like:
if("ABC".equals(getItemDescription())
return "XYZ" ;
-Prince
http://princekapoor82.blogspot.com
Maybe you are looking for
-
Can't upgrade Macbook Pro to OSX Yosemite
Hi - I've been trying to update my MacBook Pro Mid 2009 to OSX Yosemite. After dowloading and running the installer, it goes through the process of preparing the installation, closing all programs and preparing to restart. Then I get this error. I'v
-
How do you sync new music not purchased in iTunes to my iPhone
Hey there, I've always been able to sync all of my music (some purchased through iTunes, some from CDs, and some downloaded from YouTube and converted to MP3) without a problem. Recently I've noticed my new music that I've got from YouTube isn't sync
-
Docker? What is the best way to use it?
That is why I am asking on here. My company has two IT guys and I am one of them. The other guy is on a trip so I am trying to learn on my own right now
-
Panning via changes in "Position" keyframes produces pan only at *end* of clip
Hi. I am trying to create pans across relatively short time lapse shots. When I do this by making two Position keyframes, the pan occurs quickly in the last tenth of the clip or so. To make the pan play itself out across the whole clip, I have to mak
-
Why is fruit ninja not available in south africa?
why is fruit ninja not available in south africa?