Message to report the number of days worked - vba

I used below code to be informed if anyone registered in the payroll that he worked less than 30 days. It works great but the issue I have is that the message given contains the name of the employee eg. Nabil Amer worked H days.
Here I want the message to define the number of days instead of the letter "H"
Private Sub Workbook_Open()
On Error Resume Next
Dim EmpName As String
Dim RowNrNumeric As Long
Dim RowNrString As String
Dim CloumnEmpName As String
Dim CloumnNameRemStatus As String
Dim RemStatus As String
Dim Daysworked As String
Sheets("Master Payroll").Select
CloumnEmpName = "C"
CloumnNameRemStatus = "K"
Daysworked = "H"
RowNrNumeric = 2
RowNrString = RowNrNumeric
EmpName = Range(CloumnEmpName + RowNrString).Value
DueDate = Range(CloumnNameDate + RowNrString).Value
RemStatus = Range(CloumnNameRemStatus + RowNrString).Value
Do While EmpName <> ""
If Cells(RowNrNumeric, 8).Value < 30 _
And Not IsEmpty(Cells(RowNrNumeric, 2)) Then
MsgBox "WARNING: " + EmpName + " worked for " + Daysworked + " Days "
Range(Daysworked + RowNrString).Interior.ColorIndex = 3
Range(Daysworked + RowNrString).Select
End If
RowNrNumeric = RowNrNumeric + 1
RowNrString = RowNrNumeric
EmpName = Range(CloumnEmpName + RowNrString).Value
RemStatus = Range(CloumnNameRemStatus + RowNrString).Value
Loop
End Sub
Screen shot:

Change this:
MsgBox "WARNING: " + EmpName + " worked for " + Daysworked + " Days "
To this:
MsgBox "WARNING: " + EmpName + " worked for " & Range(Daysworked & RowNrNumeric).Value & " Days "

Related

TableAdapter.Update in vb.net Winform is not updating the values in the SQL Server database

I'm using a Windows Form in Visual Studio 2019 to upload an Excel file to a SQL Server database. Upload happens just fine. For simplicity; Column 'No' gets populated with values 1,2 etc. with what's included in the excel file. Column 'BUSINESS_UNIT' is left as NULL as that field is not in the excel file. What I need to do is enter a specific value, say 'ABC' for all rows of Column BUSINESS_UNIT.
No
BUSINESS_UNIT
1
NULL
2
NULL
So I'm using an update statement in my datatableadapater as below.
UPDATE MR_STAGE_SUPPLIERDELIVERY_MANUAL
SET PROCESSING_DATE = { fn NOW() },
BUSINESS_UNIT = 'ABC',
DIVISION = 'Autonomous Systems',
EAS_BUSINESS_UNIT_CD = 'TOT',
EAS_DIVISION_CD = 'AUTOSYS'
WHERE
(PERF_YEAR = #YEARINPUT) AND (PERF_MONTH = #MONTHINPUT)
This code works just as intended when I test it in Query Builder, it updates the records in SQL database. Then I added the below piece of code before debugging my winform code 'new.vb'.
Below are the functions I use to insert data from Excel to SQL database via Winform button.
Insert Function
Private Function ReturnInsertStatement(row As Integer) As String
Try
Dim tempString As String
Dim lastColumn As Integer
Dim ColumnName As String
Dim excelRange As Excel.Range
Dim filterString As String
tempString = "INSERT INTO [dbo].[MR_STAGE_SUPPLIERDELIVERY_MANUAL] (PERF_MONTH, PERF_YEAR,"
For lastColumn = 1 To 256
excelRange = objSheet.Cells(row, lastColumn)
ColumnName = excelRange.Value
filterString = "COLUMN_NAME='" + ColumnName + "'"
Dim findRow() As DataRow = BDSSMTOOLSDataSet.MR_STAGE_SUPPLIERDELIVERYNEW_COLUMNS.Select(filterString)
If findRow.Count > 0 Then
If Len(Trim(ColumnName)) > 0 Then
Me.columnsWithData = lastColumn + 1
tempString = tempString + "[" + Trim(findRow(0).Item("COLUMN_NAME").ToString) + "],"
Label5.Text = Label5.Text + " [" + Trim(Str(lastColumn)) + "]" + "(" + Trim(findRow(0).Item("DATA_TYPE").ToString) + ") " + Trim(findRow(0).Item("COLUMN_NAME").ToString) + " | "
End If
Else
If Len(Trim(ColumnName)) > 0 Then
Me.columnsWithData = lastColumn + 1
Label3.Text = Label3.Text + " [" + Trim(Str(lastColumn)) + "]" + "() " + ColumnName + " | "
End If
End If
Next
tempString = tempString.Substring(0, tempString.Length - 1) + ")"
ReturnInsertStatement = tempString
Catch ex As Exception
MsgBox(ex.ToString)
ReturnInsertStatement = ""
End Try
End Function
Return Function
Private Function ReturnValueStatement(row As Integer) As String
Try
Dim tempString As String
Dim lastColumn As Integer
Dim ColumnName As String
Dim filterString As String
tempString = " (" + perfMonthCombo.SelectedValue.ToString + "," + perfYearCombo.SelectedValue.ToString + ","
For lastColumn = 1 To Me.columnsWithData
ColumnName = excelRangeValues(row, lastColumn)
filterString = "[" + Trim(Str(lastColumn)) + "]"
If Label5.Text.Contains(filterString) Then
If Len(Trim(ColumnName)) = 0 Then
tempString = tempString + "Null,"
ElseIf Label5.Text.Contains(filterString + "(nvarchar)") Or Label5.Text.Contains(filterString + "(varchar)") Then
ColumnName = ColumnName.Replace("'", "''")
tempString = tempString + "'" + Trim(ColumnName) + "',"
ElseIf Label5.Text.Contains(filterString + "(datetime)") Or Label5.Text.Contains(filterString + "(date)") Then
Dim integerdate As Integer
If Integer.TryParse(ColumnName, integerdate) Then
ColumnName = DateTime.FromOADate(CDbl(integerdate)).ToString("MM/dd/yyyy")
End If
ColumnName = ColumnName.Replace("'", "''")
tempString = tempString + "'" + Trim(ColumnName) + "',"
Else
tempString = tempString + "" + Trim(ColumnName) + ","
End If
End If
Next
tempString = tempString.Substring(0, tempString.Length - 1) + ")"
ReturnValueStatement = tempString
Catch ex As Exception
MsgBox(ex.ToString)
ReturnValueStatement = ""
End Try
End Function
Where excel and database table is mapped
For rownum = 2 To last_row
valueString = ""
For rownum2 = 0 To 50 ' batch size
valueString = valueString + ReturnValueStatement(rownum) + ","
Label4.Text = "Rows Processing: " + Trim(Str(rownum)) + " of " + Trim(Str(last_row))
If rownum >= last_row Then Exit For
ProgressBar1.Value = rownum
rownum = rownum + 1
Next rownum2
valueString = valueString.Subs << File: VB CODE.txt >> tring(0, valueString.Length - 1)
If IsNothing(result) Then
cmd.CommandText = insertString + " VALUES " + valueString
'Console.WriteLine("T0: " + cmd.CommandText)
result = cmd.BeginExecuteNonQuery()
Else
If IsNothing(result1) Then
cmd1.CommandText = insertString + " VALUES " + valueString
' Console.WriteLine("T1: " + cmd1.CommandText)
result1 = cmd1.BeginExecuteNonQuery()
Else
cmd2.CommandText = insertString + " VALUES " + valueString
'Console.WriteLine("T2: " + cmd2.CommandText)
result2 = cmd2.BeginExecuteNonQuery()
cmdvalue2 = cmd2.EndExecuteNonQuery(result2)
'Console.WriteLine("T2: Command complete. Affected {0} rows.", cmdvalue2)
If ProgressBar2.Value + cmdvalue2 < ProgressBar2.Maximum Then
ProgressBar2.Value = ProgressBar2.Value + cmdvalue2
Else
ProgressBar2.Value = ProgressBar2.Maximum
End If
Label6.Text = "Records in the Database: " + Str(ProgressBar2.Value)
result2 = Nothing
End If
End If
If IsNothing(result) = False Then
If result.IsCompleted Or rownum >= last_row Then
cmdValue = cmd.EndExecuteNonQuery(result)
' Console.WriteLine("T0: Command complete. Affected {0} rows.", cmdValue)
If ProgressBar2.Value + cmdValue < ProgressBar2.Maximum Then
ProgressBar2.Value = ProgressBar2.Value + cmdValue
Else
ProgressBar2.Value = ProgressBar2.Maximum
End If
Label6.Text = "Records in the Database: " + Str(ProgressBar2.Value)
result = Nothing
End If
End If
If IsNothing(result1) = False Then
If result1.IsCompleted Or rownum >= last_row Then
cmdvalue1 = cmd1.EndExecuteNonQuery(result1)
' Console.WriteLine("T1: Command complete. Affected {0} rows.", cmdvalue1)
If ProgressBar2.Value + cmdvalue1 < ProgressBar2.Maximum Then
ProgressBar2.Value = ProgressBar2.Value + cmdvalue1
Else
ProgressBar2.Value = ProgressBar2.Maximum
End If
Label6.Text = "Records in the Database: " + Str(ProgressBar2.Value)
result1 = Nothing
End If
End If
Try
cmd.CommandTimeout = 10000
Me.Validate()
Me.MR_STAGE_SUPPLIERDELIVERYNEW_MANUALTableAdapter.Fill(Me.BDSSMTOOLSDataSet.MR_STAGE_SUPPLIERDELIVERYNEW_MANUAL, perfYearCombo.SelectedValue, perfMonthCombo.SelectedValue)
Me.MR_STAGE_SUPPLIERDELIVERYNEW_MANUALTableAdapter.Update(Me.BDSSMTOOLSDataSet.MR_STAGE_SUPPLIERDELIVERYNEW_MANUAL)
DataisSavedtoDB = True
perfMonthYear = Trim(perfMonthCombo.SelectedValue.ToString) + "/01/" + Trim(perfYearCombo.SelectedValue.ToString)
Label9.Text = "Current Number of Records for " + Trim(perfMonthCombo.SelectedValue.ToString) + "/" + Trim(perfYearCombo.SelectedValue.ToString) Me.BDSSMTOOLSDataSet.MR_STAGE_SUPPLIERDELIVERYNEW_MANUAL.Count.ToString
Catch ex As Exception
MsgBox(ex.ToString)
End Try
MR_STAGE_SUPPLIERDELIVERYNEW_COLUMNSTableAdapter1.Connection.Close()
When I debug this application; insert statement TableAdapter.Fill works as intended, inserting all the excel data into the SQL data, but the update statement TableAdapter.Update is not updating any of the data in my SQL database. It does not throw any error, data in SQL server database is just not updated, i.e. BUSINESS_UNIT is still NULL in database.
I attempted below solutions all day, but had no luck.
Setting dataset properties to "Do not Copy"
Wrapping up the update statement within Try Catch
Using Bindingsource.Endif() after the update statement
Attempted to use .AcceptChanges() method, but this throws an error saying that its not a member of the tableadapter
Any kind help to get this working is very much appreciated!

Type Mismatch in Dlookup

I'm getting a type mismatch in the Dlookup below. Note: the ID column in the Results2 Table is formatted as a Number.
If DLookup("[Result" & i & "]", "Results2", "[ID] = '" & newid & "'") <> Me.Controls("C" & 3 + column & "R" & i + j).Value Then
I've tried changing the newid from a string to an Integer or a Long, but I still get this error.
Full code for this Sub below, if more info is needed.
Private Sub BtnSave_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim rs3 As DAO.Recordset
Dim i As Integer
Dim j As Integer
Dim ans As Integer
Dim column As Integer
Dim colcnt As Integer
Dim newid As String
If IsNull(Me.Spindle3.Value) = False Then
colcnt = 3
ElseIf IsNull(Me.Spindle2.Value) = False Then
colcnt = 2
Else
colcnt = 1
End If
column = 1
Set db = CurrentDb
Set rs = db.OpenRecordset("Results")
Set rs2 = db.OpenRecordset("Results2")
Set rs3 = db.OpenRecordset("Results3")
Linestart:
j = 0
rs.AddNew
newid = rs![ID].Value
If Me.Result1.Value = "Fail" Or Me.Result2.Value = "Fail" Or Me.Result1.Value = "Fail" Then
If column = 1 Then
ans = MsgBox("This is a FAILING Result. Do you with to save it?", vbYesNo)
If ans = 7 Then GoTo Lineend
End If
ElseIf Me.Result1.Value = "Incomplete" Or Me.Result2.Value = "Incomplete" Or Me.Result2.Value = "Incomplete" Then
If column = 1 Then
ans = MsgBox("Testing is not finished for this part. Do you with to save and close now?", vbYesNo)
If ans = 7 Then GoTo Lineend
End If
End If
With rs
![PartNum] = Me.FilterPartNumber.Value
![INDNum] = Me.INDNum.Value
![DateTime] = Me.DateTime.Value
![HTLotNum] = Me.HTLotNum.Value
![Operator] = Me.Inspector.Value
![Spindle] = Me.Controls("Spindle" & column).Value
![TypeofCheck] = Me.InspType.Value
![OverallResult] = Me.Controls("Result" & column).Value
End With
rs2.AddNew
With rs2
![ID] = newid
![PartNum] = Me.FilterPartNumber.Value
![Plant] = Me.plantnum.Value
![DateTime] = Me.DateTime.Value
![HTLotNum] = Me.HTLotNum.Value
![Notes] = Me.Notes.Value
![Spindle] = Me.Spindle.Value
![TypeofCheck] = Me.InspType.Value
![OverallResult] = Me.Result1.Value
End With
rs3.AddNew
With rs3
![ID] = newid
![PartNum] = Me.FilterPartNumber.Value
![DateTime] = Me.DateTime.Value
End With
If IsNull(Me.HTLotNum.Value) = True Then
rs![HTLotNum] = "(blank)"
rs![HTLotNum] = "(blank)"
End If
For i = 1 To 90 Step 1
If i + j >= 90 Then
i = 90
GoTo Line1
End If
If IsNull(Me.Controls("C3R" & i + j).Value) = True Then
j = j + 1
End If
If i + j >= 90 Then
i = 90
GoTo Line1
End If
If IsNull(Me.Controls("C2R" & i + j).Value) = True Then GoTo Line1
rs("Char" & i) = Me!ListFeatures.column(1, i - 1)
rs("Desc" & i) = Me!ListFeatures.column(2, i - 1)
rs("Spec" & i) = Me!ListFeatures.column(3, i - 1) & " " & Me!ListFeatures.column(6, i - 1)
rs2("SC" & i) = Me!ListFeatures.column(4, i - 1)
rs2("Location" & i) = Me!ListFeatures.column(5, i - 1)
rs2("Result" & i) = Me.Controls("C" & 3 + column & "R" & i + j).Value
rs3("Coding" & i) = Me!ListCoding.column(1, i - 1)
Line1:
Next
rs.Update
rs2.Update
rs3.Update
For i = 1 To 90 Step 1
If i + j >= 90 Then
i = 90
GoTo Line1
End If
If IsNull(Me.Controls("C3R" & i + j).Value) = True Then
j = j + 1
End If
If i + j >= 90 Then
i = 90
GoTo Line1
End If
If DLookup("[Result" & i & "]", "Results2", "[ID] = '" & newid & "'") <> Me.Controls("C" & 3 + column & "R" & i + j).Value Then
MsgBox "Results not saved! Document results on paper and contact the database engineer regarding this error."
GoTo Lineend:
End If
Next
If column < colcnt Then
column = column + 1
GoTo Linestart
End If
Line2:
Forms![Landing Page]![LIstIncomplete].Requery
DoCmd.Close
Lineend:
End Sub
Per one of the comments, I updated the trouble line to the line below. I'm almost certain that was how I initially wrote this line and added the apostrophes as an attempt to fix.
If DLookup("[Result" & i & "]", "Results2", "[ID] = " & newid) <> Me.Controls("C" & 3 + column & "R" & i + j).Value Then
I had to fix one of my Goto's as well, one of them led to an infinite loop, but now everything is working as intended.
Thanks for the help!

Getting Source object from footnote (word vba)

I create footnotes which contains Source objects (a Source object is a single object from Sources list, from which I create Bibliography)
All I want to do is to loop through all footnotes and get XML file from each Source object to retrieve information about Author and so on.
I have problem with getting Source object from footnotes. I tried to select footnote and retrieve this object from selection but nothing works. Maybe You guys have a proper way to retrieve "parent object" from another object in vba?
Sub convertAllFootnotes()
Dim ftn As Footnote
Dim oRng As Range
For Each ftn In ActiveDocument.Footnotes
Set oRng = Selection.Range
oRng.Start = oRng.Start - 1
oRng.End = oRng.End + 1
oRng.Select
oRng.Text = stringFromSource(ftn) 'i don't know how to get source object
'from footnote
Next ftn
End Sub
string from source function (which works properly, i must pass to it Surce object)
Function stringFromSource(curField As Source) As String
Set xmlDoc = CreateObject("MSXML2.DOMDocument")
xmlDoc.LoadXML curField.XML
authors = "": title = "": publish = "": city = "": year = "": periodic =
""
'authors
Set surname = xmlDoc.getElementsByTagName("b:Last")
Set name = xmlDoc.getElementsByTagName("b:First")
Dim l As Integer
l = 0
For Each el In surname
If el.Text = "" Then Exit For
authors = authors + (el.Text & " " & name(l).Text & " ")
l = l + 1
Next el
'title
Set titlex = xmlDoc.getElementsByTagName("b:Title")
For Each el In titlex
If el.Text = "" Then Exit For
title = title + (el.Text & " ")
Next el
'publisher
Set pubx = xmlDoc.getElementsByTagName("b:Publisher")
For Each el In pubx
publish = publish + (el.Text & " ")
Next el
'city
Set cityx = xmlDoc.getElementsByTagName("b:City")
If cityx.Length = 0 Then city = city + ("(brak miasta)" & " ")
For Each el In cityx
city = city + (el.Text & " ")
Next el
'year
Set yearx = xmlDoc.getElementsByTagName("b:Year")
If yearx.Length = 0 Then year = year + ("(brak roku wydania)" & " ")
For Each el In yearx
year = year + (el.Text & " ")
Next el
'periodical title
Set periodx = xmlDoc.getElementsByTagName("b:PeriodicalTitle")
For Each el In period
periodic = periodic + (el.Text & " ")
Next el
Dim outputString As String
outputString = author & "- " & title & ", " & publish & periodic & ", " &
year
stringFromSource = outputString
End Function

Updating Alternative text of a button

I have the following code as part of a Job site labor form, which links a full labor call on the "LocLabor" sheet to various single day sign in sheets. This particular code is to add a complete day to the form, and works great, with the exception of these two lines at the bottom:
.Buttons(bnum).ShapeRange.AlternativeText = dayint + 1
.Buttons(bnum + 1).ShapeRange.AlternativeText = dayint + 1
The "scopy", "ecopy", and "brow" variables are used to work out the appropriate lines to copy and paste to the next day. The buttons that are being altered are the newly pasted buttons that were copied within the scopy/ecopy range and are used to add or delete a line from the table they refer to. I need to be able to change the AltText because I am using that as a reference for which day of the labor call they apply to. The "numdays" variable pulls from locsht.Range("L3").Value, which is set to the current number of days on the form prior to running the macro. So it would have a value of 2 when I see the error
Now to the issue - if I have two days existing in the document and I execute the below code, the name of the button changes, but the Alternative Text does not (it remains as "2" or whatever it was prior to copying). Days 4 and up work perfectly though, it is just the transition from day 2 to 3 that I cannot get to work! It also works if I switch out "dayint + 1" to a string, like "banana" for example, but that obviously doesn't help me.
Any ideas would be appreciated.
Option Explicit
Sub add_day()
Dim numdays As String
Dim tbl As TableStyle
Dim newsht As Worksheet
Dim locsht As Worksheet
Dim scopy As Integer
Dim ecopy As Integer
Dim brow As Integer
Dim dayint As Integer
Dim bnum As Integer
Dim tblstart As String
Application.ScreenUpdating = False
'unlock sheet
Worksheets("LocLabor").Unprotect Password:=SuperSecretPW
'set/get variables
Set locsht = Worksheets("LocLabor")
numdays = locsht.Range("L3").Value
dayint = numdays
Worksheets("Labor Sign In Day " & numdays).Copy Before:=Sheets(numdays + 4)
Worksheets("Labor Sign In Day " & numdays & " (2)").Name = "Labor Sign In Day " & numdays + 1
'update number of days on sheet
locsht.Range("L3") = locsht.Range("L3").Value + 1
'rename new sign in sheet
Set newsht = Worksheets("Labor Sign In Day " & numdays + 1)
newsht.Unprotect Password:=SuperSecretPW
'figure out which rows to copy on main sheet
scopy = locsht.ListObjects(dayint).Range.Rows(1).Row - 1
brow = locsht.ListObjects(dayint).Range.Rows.Count
ecopy = scopy + brow
'Copy/paste new day on LocLabor
locsht.Activate
locsht.Rows(scopy & ":" & ecopy).Copy
locsht.Rows(ecopy + 2).Insert Shift:=xlDown
locsht.ListObjects("Tableday" & numdays).Resize Range("A" & scopy + 1 & ":" & "H" & ecopy)
locsht.Range("A" & ecopy + 2 & ":" & "H" & ecopy + 2) = "=IFERROR($A$17+" & numdays & "," & """Enter Load in Date at Top"")"
locsht.Rows(ecopy + 1).EntireRow.Delete
locsht.PageSetup.PrintArea = "$A$1:$H$" & ecopy + (ecopy - scopy + 1)
locsht.HPageBreaks.Add Before:=locsht.Rows(ecopy + 1)
locsht.ListObjects(dayint + 1).Name = "Tableday" & numdays + 1
bnum = (dayint * 2) + 3
tblstart = locsht.ListObjects(dayint + 1).Range.Rows(1).Row + 1
'Enter correct formulas into sign in sheet
With newsht
.ListObjects(1).Name = "signinday" & numdays + 1
.Range("i12") = Left(newsht.Range("i12").Formula, 28) & numdays & Right(newsht.Range("i12").Formula, 48)
.Range("A17") = "=IF(ISBLANK(LocLabor!G" & tblstart & ")=FALSE,LocLabor!G" & tblstart & "&"" ""&LocLabor!F" _
& tblstart & ",IF(ISBLANK(LocLabor!D" & tblstart & ")=TRUE," & """""" & ",LocLabor!D" & tblstart & "))"
.Range("B17") = "=IF(ISBLANK(LocLabor!B" & tblstart & ")=TRUE, """", LocLabor!B" & tblstart & ")"
.Range("G17") = "=IF(ISBLANK(LocLabor!C" & tblstart & ")=TRUE, """", LocLabor!C" & tblstart & ")"
End With
'rename pasted buttons, update alttext
With locsht
.Buttons(bnum).Name = "Button " & bnum
.Buttons(bnum + 1).Name = "Button " & bnum + 1
.Buttons(bnum).ShapeRange.AlternativeText = dayint + 1
.Buttons(bnum + 1).ShapeRange.AlternativeText = dayint + 1
End With
'lock down sheets
Worksheets("LocLabor").Protect Password:=SuperSecretPW, DrawingObjects:=False, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingRows:=True, _
AllowInsertingRows:=True, AllowDeletingRows:=True, AllowSorting:=True, _
AllowFiltering:=True
Worksheets("LocLabor").EnableSelection = xlUnlockedCells
Worksheets("Labor Sign In Day " & numdays + 1).Protect Password:=SuperSecretPW, DrawingObjects:=False, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingRows:=True, _
AllowInsertingRows:=True, AllowDeletingRows:=True, AllowSorting:=True, _
AllowFiltering:=True
Worksheets("Labor Sign In Day " & numdays + 1).EnableSelection = xlUnlockedCells
ActiveSheet.Buttons(Application.Caller).TopLeftCell.Offset(3, 0).Select
Application.ScreenUpdating = True
End Sub

Search between two dates w/ datarows in vb 2010

I am trying to search between two dates in a bound source (SQL table) in VB 2010, using data rows. Since 'between' in unsupported with the data rows function, I used < and >.
So I run this code and the output is 900+ entries when the actual number of entries is 8. After hitting my button a second time without changing anything, the correct number of entries appears.
Private Sub cmdSearch_Click(sender As System.Object, e As System.EventArgs) _
Handles cmdSearch.Click
Dim Expression As String
Dim OrderStr As String = "Area"
Dim DateStr As String
Dim StartDate As String
Dim EndDate As String
Dim Shift As String = ""
Dim Area As String = ""
Dim Product As String
If (DtpStartDate.Value = Nothing Or DtpEndDate.Value = Nothing) Then
MsgBox("Please input a start and end date.")
Exit Sub
End If
If (radShiftAllSearch.Checked <> True _
And radShiftOneSearch.Checked <> True
And radShiftTwoSearch.Checked <> True _
And radShiftThreeSearch.Checked <> True) Then
MsgBox("Please select a shift to search for.")
Exit Sub
End If
Select Case True
Case radShiftOneSearch.Checked
Shift = " AND [Shift] = '1'"
Case radShiftTwoSearch.Checked
Shift = " AND [Shift] = '2'"
Case radShiftThreeSearch.Checked
Shift = " AND [Shift] = '3'"
Case radShiftAllSearch.Checked
Shift = " AND ([Shift] = '1' OR [Shift] = '2' OR [Shift] = '3')"
End Select
**StartDate = DtpStartDate.Value.Subtract(oneday)
EndDate = DtpEndDate.Value.Add(oneday)
'StartDate = Format(DtpStartDate.Value.Subtract(oneday), "M/dd/yyyy")
'EndDate = Format(DtpEndDate.Value.Add(oneday), "M/dd/yyyy")
DateStr = "[Dates] > '" & StartDate & "' AND [Dates] < '" & EndDate & "'"**
If (txtProductSearch.Text = "") Then
Product = ""
Else
Product = "AND [Product] LIKE '" & txtProductSearch.Text & "'"
End If
For h As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
Dim XDRV As DataRowView = CType(CheckedListBox1.CheckedItems(h), DataRowView)
Dim XDR As DataRow = XDRV.Row
Dim XDisplayMember As String = XDR(CheckedListBox1.DisplayMember).ToString()
If (Area = "") Then
Area = Area & " AND ([Area] LIKE '" & XDisplayMember & "'"
Else
Area = Area & " OR [Area] LIKE '" & XDisplayMember & "'"
End If
Next
If (Area <> "") Then
Area = Area & ")"
End If
Expression = DateStr & Product & Shift & Area
TextBox4.Text = Expression
Dim SearchRows() As DataRow = _
ProductionDataSet.Tables("Production_Daily").Select(Expression, OrderStr)
'foundcount = SearchRows.Count - 1
DataGridView1.DataSource = SearchRows
DataGridView1.Show()
End Sub
Thanks