I export excel in protected or using password manner and there is a chance to unprotect the sheet. I want that, there is no option to edit after export the excel in vb.net.
To make a column non-editable:
Select the whole worksheet, Right Click->Format Cells->Protection, uncheck the "Locked" check box.
Select the column you want to protect, right Click->Format Cells->Protection, select the "Locked" check box.
Review tab->Protect Sheet, select the "Protect worksheet and contents of locked cells" check box and protect the sheet using a password.
Related
In snowfake how can you open a new worksheet with the same connectons for role, datawarehouse and schema? Everytime I open a new worksheet it removes all my settings and have to select them again
you need to set the default_warehouse and default_namespace user parameters to the values you want to be used when you create a new sheet.
These defaults will be used for every new sheet. As far as I'm aware, there is no way to automatically create a sheet with the same context as a previous sheet - in case that is what you are trying to achieve.
I am pulling a report from SQL in Excel. I got it all working, except I need multiple user prompts (one parameter with multiple values).
I decided to use a listbox which contains all the possible selection that I want the user to choose from (These values are on another sheet in the same workbook) and then when a button is clicked, it displays the information in that same worksheet base on the selected choices the user choose.
This information that is being displayed is coming straight from SQL server.
I tried using a userform in VBA in Excel, but I am still not quite sure how to have it pull from SQL base on the selections in the listbox.
I had it where the information was displayed, except I was only able to input one parameter at a time. I want the user to be able to do multiple selections and then the information is displayed.
In my query I had wmav_code = ? to prompt the user to input what code they wanted, but as stated before, it generates a report base on that one value. I tried wmav_code in (?,?,?,?), however, that's limiting the prompts to 4. I have 97 various codes to choose from (Hence the decision to use a listbox).
I tried (InStr(?, [wmav_code])>0), but Excel 2016 does not recognize that function (InStr()).
P.S. These are all within the 'WHERE' clause.
I don't have to use a listbox, a simpler route/method would be appreciated.
When I try to import date values from Excel into SQL Server and the values contain zero date like this 2013-01-00, these are saved in the database as null value. How can I fix this problem?
You do not state the method/environment you are using for importing, so general suggestions are:
Do a specific replacement:
If (ImportValue = '2013-01-00') Then Import('1/1/1970') Else Import(ImportValue)
Do an IsDate test and replacement:
If IsDate(ImportValue) Then Import(ImportValue) Else Import('1/1/1970')
After import, use SQL to replace all null date values, and change to a real date
Let us know what environment you are using for better example.
Since you are using the wizard, you will not get a chance to create an "If ... Then ..." statement, but it is easy to import the data then change the NULL values using the SQL Server Management Studio (SQL-SMS) tools.
To use the Wizard to import Excel data into SQL Server:
Launch the Import and Export Data (32-bit), click Next
Specify Excel Data Source and workbook name,
Hopefully, the existing spreadsheet has column names in the first row
if so then check "First row has column names"
click Next
Choose the Destination SQL Server, Authentication, and Database, click Next
Click "Copy data from one or more tables or views", click Next
Check-mark the Sheet within the workbook you want to import from
If you want a specific table name, edit the "Destination" column
For this example, I am importing to table "TestExcelImport"
Make sure the desired Source Sheet stays hi-lighted, click the "Edit Mappings" button,
depending on if the spreadsheet had column names in the first row
you may see those column names in the "Source" column
you can change the "Destination" column names if you prefer a different field name
you can click the "Preview..." button to see approximately what your imported data will look like
click Next
Check-mark "Run immediately", click Next
Review the summary
you should see something like "Copy rows from 'Sheet1$' to [TestExcelImport]"
click Finish
The wizard will execute, and show you details of the process
click Close
To update the rows where the date field is NULL:
Open SQL-SMS, connect to the SQL Server you imported to
Browse to the database, then expand "Tables"
Tip: if you already had SQL-SMS open, you may need to right-click "Tables" and select "Refresh"
Right-click the table you imported to, then click "Edit top 1000 rows"
In my example above, this would be table "TestExcelImport"
You should see your table with it's data (including some NULL date values)
We want to filter for records that have NULL date values,
From the menu, choose: Query Designer > Pane > Criteria
Tip: you can optionally choose to see the SQL pane also, handy for studying SQL syntax
In the upper "Criteria" pane, find the date row, then over in the "Filter" column type: null
(it will change to "IS NULL" automatically)
click the red exclamation mark button in the toolbar, labeled "Execute SQL"
you will see in the lower pane, only the records that have NULL for date
Change the Query Type to update records
From the menu, choose: Query Designer > Change Type > Update
You will now in the upper "Criteria" pane an new column named "New Value"
In the date value row, in the "New Value" column, specify the date you want to replace NULL
Example: type "1/1/1980" in the "New Value" column if you want that date to replace all NULL date values
Note: be SURE the "IS NULL" is still in the "Filter" column
click the red exclamation mark button in the toolbar to run the UPDATE query.
Close then re-open this table to see NULL date values replaced with 1/1/1980
Optionally: do a "Change Type" back to "Select", and remove the "IS NULL" filter
Hope this helps!!
(68m)
I created a form in Visual Studio 2012 binding table 1 to a few of the fields in order to force the user to use specific data in both a textbox and a combobox. They select what they need out of those fields, and fill in a few others, and then click save, which will take the data to table 2. While I've created a dataset, bindingsource, tableadapter, and tableadaptermanager for table 2, it does not save to the table if I use...
Me.Validate()
Me.table2BindingSource.EndEdit()
Me.table2TableAdapter.Update(table2DataSet)
...like you can if you use the bound source that's autofilling the form. How do I wire the save to hit the proper table? Do I have to go the long way and open up a connection creating the sql statement, executing that business, etc.?
So I did have to code the connection sequence into the button click. I've included the code below for posterity and comment.
Using connection As New SqlClient.SqlConnection(My.Settings.MyConnectionString)
Using Command As New SqlClient.SqlCommand("INSERT INTO table2 (stuff1, stuff2, stuff3) VALUES (#stuff1, #stuff2, #stuff3)", connection)
Command.Parameters.AddWithValue("#stuff1", stuff1TextBox.Text)
Command.Parameters.AddWithValue("#stuff2r", stuff2ComboBox.Text)
Command.Parameters.AddWithValue("#stuff3", stuff3TextBox.Text)
connection.Open()
Command.ExecuteNonQuery()
Dim rowsAffected As Integer = Command.ExecuteNonQuery()
Console.WriteLine("RowsAffected: {0}", rowsAffected)
End Using
It worked well enough for me to be comfortable and submit it for user testing. Please feel free to pull it apart.
I have an Access database that I use to to run a bunch of aggregate TOP 5 queries. The end game of this particular function is ppt presentations with charts. So to automate this a bit, I created an excel spreadsheet with a bunch of pre-made charts in it. The I linked/data imported the query results into the excel spreadsheet, and set the cell ranges to match the source ranges for the charts. Finally I set the spreadsheet to enable auto refresh upon every "file open", and presto, I run the queries in access with a button press, then open the excel file, and the data refreshes, and they are my charts. I then use some VB to copy paste all active charts into ppt, but that is another matter.
Okay so here is the snag I hit. I needed to do the exact same procedure with another spreadsheet from another ag query. Before the process I was using was just clicking data > import external data > import data and then choosing the file of the database, and then it would populate a list of tables and queries to choose from. Only now, it will not show any queries in that populated list; only tables!?!
any ideas? btw MSO 2003
I can't reproduce that Justin. In the dialog that shows the tables, scroll over to the right and check the TYPE column. Queries will have a type of VIEW and tables of TABLE. Verify that they all say TABLE.
Next, try using Data - Import External Data - New Database Query instead of 'Import Data'. Select the Access driver and the Access mdb. This will bring up a different dialog, but should show both tables and queries. See if that shows only tables or shows both.
I presume this is a security feature that has been introduced?
Try selecting any table then select Data>Import External Data>Edit Query
Then select SQL as the command type and either enter the query SQL or just select from a query i.e.:
select * from qryCat;
Hope this helps
thanks Mark