Skip to content

Instantly share code, notes, and snippets.

View NPS-ARCN-CAKN's full-sized avatar

NPS Arctic and Central Alaska Inventory and Monitoring Networks NPS-ARCN-CAKN

View GitHub Profile
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / PersistColumnOrderAccess2010.txt
Last active October 26, 2023 14:45
Microsoft Access 2010 fix for datasheet view column order not persisting with save
I encountered a bug in Microsoft Access 2010 where I would open a form in split view or datasheet view,
rearrange the order of columns, save the form, re-open the form and the column order would not reflect
the columns order I had tried to save.
Solution:
1. Open the form in datasheet view
2. Re-order the columns
3. Right-click a column header and click Unhide fields
4. Close the Unhide fields dialog
5. Save the form and re-open
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / GetDataTable.vb
Created January 5, 2017 15:35
VB .Net: A function to return a DataTable from a database connection.
''' <summary>
''' Returns a DataTable from a database query defined by a ConnectionString.
''' </summary>
''' <param name="ConnectionString">ConnectionString to a database</param>
''' <param name="Sql">An SQL query</param>
''' <returns>DataTable</returns>
Private Function GetDataTable(ConnectionString As String, Sql As String) As DataTable
'the DataTable to return
Dim MyDataTable As New DataTable
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / Sql: Select distinct values into comma separated list.sql
Last active May 10, 2022 15:19
Sql: Select distinct values into comma separated list
DECLARE @Packs AS NVARCHAR(MAX)
select @Packs = STUFF((SELECT DISTINCT ',' + QUOTENAME(LTRIM(RTRIM(Pack))) from basequeryTotalPupsByRegion FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'),1,1,'')
select @Packs
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / OpenFileDialogExample.vb
Created April 30, 2015 13:03
VB .NET: An example OpenFileDialog function
Private Function OpenFile() As String
'build and configure an OpenFileDialog
Dim OFD As New OpenFileDialog
With OFD
.AddExtension = True
.CheckFileExists = True
.Filter = "Excel files(.xlsx)|*.xlsx|Excel files (*.xls)|*.xls"
.Multiselect = False
.Title = "Select an workbook to open"
End With
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / GetCurrentGridEXCellValue.vb
Created August 23, 2019 17:13
Function to return the current cell value of a GridEX
''' <summary>
''' Returns the value of GridEX's current cell, if it exists, otherwise an empty string.
''' </summary>
''' <param name="GridEX">GridEX</param>
''' <param name="ColumnName">Name of GridEX cell to interrogate.</param>
''' <returns>String</returns>
Private Function GetGridEXCellValue(GridEX As GridEX, ColumnName As String) As String
Dim CellValue As String = ""
'the gridex contains a column called FilesDirectory where the project's files are stored
'this sub will get the currently selected row in the GridEX, identify the FilesDirectory value
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / AddItemToMultiColumnListViewItem.vb
Last active April 5, 2018 19:58
VB .NET: Add items to a multi-column ListViewItem
'Me.ItemsListView has two columns, one for the file name and one for the full file path
Dim FileAttributes(2) As String
FileAttributes(0) = FileInfo.Name
FileAttributes(1) = FileInfo.FullName
Dim ListViewItem As New ListViewItem(FileAttributes)
Me.ItemsListView.Items.Add(ListViewItem)
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / LoopSpecialFolders.vb
Created April 5, 2018 18:18
VB .NET: Loop through Environment.SpecialFolders
For Each SpecialFolder As Environment.SpecialFolder In System.Enum.GetValues(GetType(Environment.SpecialFolder))
Debug.Print(System.Environment.GetFolderPath(SpecialFolder))
Next
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / LoopThroughSpecialFoldersEnum.vb
Created April 5, 2018 18:02
VB .Net: Loop through an Enum (SpecialFolders)
For Each SpecialFolder As String In System.Enum.GetNames(GetType(Environment.SpecialFolder))
Debug.Print(SpecialFolder)
Next
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / GetMetadataDataTable.vb
Created January 2, 2018 22:38
A function to return a DataTable of metadata about a DataTable
''' <summary>
''' Returns a DataTable containing metadata about the structure of the submitted DataTable
''' </summary>
''' <param name="InputDataTable">DataTable to describe.</param>
''' <returns>DataTable</returns>
Public Function GetMetadataDataTable(InputDataTable As DataTable) As DataTable
Dim ColumnsDataTable As New DataTable("Columns")
'column names column
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / GetGridEXCellValue.vb
Created December 4, 2017 21:50
Get the value of a GridEX cell (Visual Basic .NET)
'the gridex contains a column called FilesDirectory where the project's files are stored
'this sub will get the currently selected row in the GridEX, identify the FilesDirectory value
'and attempt to open the path using a process (file explorer, most likely)
Try
'get the current row of the VS GridEX
If Not Me.TblVitalSignsGridEX.CurrentRow Is Nothing Then
Dim CurrentRow As GridEXRow = Me.TblVitalSignsGridEX.CurrentRow
'loop through the columns and look for the FilesDirectory columns
For i As Integer = 0 To CurrentRow.Cells.Count - 1
If CurrentRow.Cells(i).Column.Key = "FilesDirectory" Then