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 / AccessFeatureClassData.py
Last active December 17, 2015 19:29
ArcPy: Access feature class data
import arcpy
import numpy
input = r"C:\Work\Waypoints.shp"
arr = arcpy.da.FeatureClassToNumPyArray(input, ('ident', 'Latitude', 'Longitude'))
for row in arr:
ident = row["ident"]
lat = row["Latitude"]
lon = row["Longitude"]
sql = "INSERT INTO MyTable(WaypointName,Lat,Lon) VALUES('" + str(ident) + "'," + str(lat) + "," + str(lon) + ");"
print sql
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / ToggleFormEditability.vb
Last active December 21, 2015 16:28
Access: Toggle a form's editability (Read only/Editable)
' this button allows the user to switch between read only and editing
Private Sub ToggleReadOnlyButton_Click()
SetFormEditability
End Sub
' you can only toggle the form's allowedits property is it is clean so if the
' form is dirty then ask if it's ok to flush changes
Private Sub SetFormEditability()
If Me.Dirty = True Then
If MsgBox("Save changes?", vbYesNo, "Confirm") = vbYes Then
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / BindTextBoxToDataGridViewCell.vb
Last active December 24, 2015 13:13
Bind TextBox to DataGridViewCell
Private Sub VitalSignDataGrid_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles VitalSignsDataGridView.CellClick
Me.LogEntryRichTextBox.DataBindings.Add("Text", Me.WorkLogDataGridView.DataSource, "LogEntry")
End Sub
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / MasterDetailDataGridViewsForm.vb
Last active December 24, 2015 13:06
Set up a master/detail DataGridViews form from two related database tables
'adapted from https://msdn.microsoft.com/library/y8c0cxey%28v=vs.100%29.aspx
Dim MyDataset As New DataSet
Private Sub WorkLogForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'set up the master data table
Dim VitalSignsSqlConnection As New SqlConnection(My.Settings.ConnectionString)
Dim VitalSignsDataAdapter As New SqlDataAdapter("SELECT [Acronym],[NetworkVSName] as VitalSign,[VSID] FROM vwVitalSignsMatrix", VitalSignsSqlConnection)
VitalSignsSqlConnection.Open()
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / QuerySQLServerDatabaseUsingPYODBC.py
Created January 6, 2016 16:03
Query a SQL Server Database Using PYODBC
import pyodbc
connection = pyodbc.connect(r'Driver={SQL Server};Server=MyServerName;Database=MyDatabase;')
cursor = connection.cursor()
cursor.execute("SELECT * FROM MyTable")
row = cursor.fetchone()
if row:
print row
connection.close()
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / QueryPointsToLineUsingSQL.sql
Created January 6, 2016 19:50
Query points to a line using SQL
-- adapted from http://stackoverflow.com/questions/24259914/create-geography-line-from-points-in-t-sql
DECLARE @BuildString NVARCHAR(MAX)
SELECT @BuildString = COALESCE(@BuildString + ',', '') + CAST(Location.Long AS NVARCHAR(50)) + ' ' + CAST(Location.Lat AS NVARCHAR(50))
FROM dbo.Locations
WHERE SurveyID = '20120103130303-533424019.813538'
ORDER BY CaptureDate
SET @BuildString = 'LINESTRING(' + @BuildString + ')';
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / MoveToFormRecordUsingListBox.vb
Last active April 5, 2016 22:00
Move to a record in a form using a ListBox
Private Sub SurveyFlightChooserComboBox_AfterUpdate()
On Error GoTo Error
'move to the selected record
Me.RecordsetClone.FindFirst "[FlightID] = '" & Me![SurveyFlightChooserComboBox] & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark
Exit Sub
Error:
MsgBox Err.Description & " (SurveyFlightChooserComboBox_AfterUpdate)"
Exit Sub
End Sub
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / 24HourTimeIntegerToTimeString.vb
Created January 14, 2016 16:38
24 Hour Time Integer to Time String
'calculate the difference in minutes between two time strings in 4 character 24 hour time format
StartTime24Hr = Left(StartTime24Hr, 2) & ":" & Right(StartTime24Hr, 2)
EndTime24Hr = Left(EndTime24Hr, 2) & ":" & Right(EndTime24Hr, 2)
TimeString = DateDiff("n", StartTime24Hr, EndTime24Hr)
@NPS-ARCN-CAKN
NPS-ARCN-CAKN / StuckServerFilter.vb
Last active April 5, 2016 13:26
Microsoft Access Form ServerFilter Property Gets Stuck
' this sometimes solves the sticky serverfilter problem
Private Sub Form_Unload(Cancel As Integer)
Me.ServerFilter = ""
Me.Refresh
End Sub
@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