I have a problem with my UPDATE function. The programme should ask the user if he wants to overwrite one record which is already in the table. So I thought the following code would do it:
Dim strSQL As String
Dim Box As String
If DCount("*", "tblEvents", "Event = '" & Me!EventName & "' AND Date1= " & Format(CDate(Me!Date1), "\#yyyy-mm-dd\#")) > 0 Then
Box = MsgBox("There is already a price for the event on the selected date. Do you want to overwrite the price?", vbYesNo)
If Box = vbNo Then
Cancel = True
Else
strSQL = "UPDATE tblEvents SET Price = '" & Me!Price & "' WHERE Event = '" & Me!EventName & "' AND Date1 = " & Format(CDate(Me!Date1), "\#yyyy-mm-dd\#)")
End If
Else [Save new record]
End If
The code runs but it doesn't overwrite the price...
Please try below code:
Dim strSQL As String
Dim Box As String
'Declare variables for your controls here so that you can check what value it returns in debug mode
Dim EventName As String = Me!EventName
Dim Price As String = Me!Price
Dim Date1 As String = Format(CDate(Me!Date1), "\#yyyy-mm-dd\#")
If DCount("*", "tblEvents", "Event = '" & EventName & "' AND Date1= " & Date1) > 0 Then
Box = MsgBox("There is already a price for the event on the selected date. Do you want to overwrite the price?", vbYesNo)
If Box = vbNo Then
Cancel = True
Else
strSQL = "UPDATE tblEvents SET Price = '" & Price & "' WHERE Event = '" & EventName & "' AND Date1 = " & Date1
'Your SQL execute code here
End If
Else
'Your SQL execute code here for Save
End If
End Sub
Now that you get the values of Price,EventName and Date1, try to execute your update query in access editor just to test if the values you get from you code is really working.
UPDATE tblEvents SET Price = '123' WHERE Event = 'party' AND Date1 ='2016/09/23'
Related
My Project is developed in MS-Access 2010 and Back end is SQL Server 2016.I connect the back end with ODBC. I install the system in my PCs and it working good but in one PC, whenever the user try to submit he get the same error
! [Error image] https://ibb.co/fCV6JGF
I delete the old ODBC connection and create a "New" connection through SQL Server.Before I replace the Source code folder with new one.But the same Error occur.
Private Sub cmdPostSubmit_Click()
postSubmit = 1
postOnly = 0
If TestOutlookIsOpen = True Then
Else
If UCase (Trim(Me.cboAllStatus.Value)) = "STEPPED UP" Then
MsgBox "Outlook is not open", vbCritical + vbOKOnly
Exit Sub
End If
End If
If (Nz(Trim(DLookup("fldAllStatus", "TBL_REQUEST_STATUS","fldTrackNo=
'" & gTrackNo & "'"))) = "Unprocessed")
Then Msgbox "attach the docs",vbCritical + vbOKOnly
Exit Sub
If Me.cmdPostSubmit.Caption = "Submit" Then
If (Trim(DLookup("fldUnitName", "TBL_USER", "fldNetID = '" & Trim(gNetID) & "'")) = Trim(hostUNIT)) Then
'If (Nz(DLookup("count(fldTrackNo)", "TBL_FILE_ATTACHMENT", "fldTRackNo = '" & gTrackNo & "'")) = 0 And Me.chkRet.Value = 0) Then
' MsgBox "This request must be returned and cannot be processed due to lack of attachments.", vbInformation + vbOKOnly
' Exit Sub
'End If
If (Me.chkRet.Value = -1) Then
If MsgBox("Are your sre you want to return this request unrpocessed ?", vbQuestion + vbYesNo) = vbYes Then
If Nz(Me.txtRemarks.Value) = "" Then
MsgBox "Please write something in the remarks to proceed ... ", vbInformation + vbOKOnly
Exit Sub
Else
'Save the current request status prior to updating
saveUnprocessedStatus gTrackNo, Trim(DLookup("fldAllStatus", "TBL_REQUEST_STATUS", "fldTrackNo = '" & gTrackNo & "'"))
CurrentDb.Execute "UPDATE TBL_REQUEST_STATUS SET fldAllStatus = 'Unprocessed',fldReqStatus = 'Unprocessed' WHERE fldTrackNo = '" & gTrackNo & "'"
CurrentDb.Execute "UPDATE TBL_REQUEST_APPROVAL SET fldReqStatus = 'Unprocessed' WHERE fldTrackNo = '" & gTrackNo & "'"
End If
Else
Exit Sub
End If
End If
If Nz(Me.txtRemarks.Value) = "" Then
MsgBox "Please write something in the remarks ... ", vbInformation + vbOKOnly
Exit Sub
End If
End If
updateValuesDetails 'Download and update the details
MsgBox "Request Successfully Posted And Submitted !!!", vbInformation + vbOKOnly
If UCase(Trim(Me.cboAllStatus.Value)) = "STEPPED UP" Then
clsMail.sendMailForStepUpRequest
End If
Else
uploadValuesDetails 'Download and save the details
MsgBox "Request Successfully Posted And Submitted !!!", vbInformation + vbOKOnly
If UCase(Trim(Me.cboAllStatus.Value)) = "STEPPED UP" Then
clsMail.sendMailForStepUpRequest
End If
disableMainButt 0
Forms![FRM_MAIN].Form.cmdNewRequest.SetFocus
Forms![FRM_MAIN]![subForm].SourceObject = "FRM_REQ_STATUS"
'' RELOAD MASTER LIST
strSQL = "SELECT TBL_REQUEST_STATUS.fldTrackNo,TBL_REQUEST_STATUS.fldJobTitle, TBL_REQUEST_STATUS.fldReqStatus, TBL_REQUEST_STATUS.fldDateInitiated,"
strSQL = strSQL & "TBL_REQUEST_STATUS.fldReqBy, TBL_REQUEST_STATUS.fldUnitApp, TBL_REQUEST_STATUS.fldEDURec, TBL_REQUEST_STATUS.fldEDUApp,"
strSQL = strSQL & "TBL_REQUEST_STATUS.fldPercentage, TBL_WORKFLOW_APPROVAL.fldUnitApproved, TBL_WORKFLOW_APPROVAL.fldEDUEvaluated, TBL_WORKFLOW_APPROVAL.fldEDUApproved,"
strSQL = strSQL & "TBL_WORKFLOW_APPROVAL.fldDivApproved,TBL_REQUEST_APPROVAL.fldNetID,TBL_WORKFLOW_APPROVAL.fldAssignedEngr,TBL_REQUEST_STATUS.fldAllStatus,TBL_REQUEST_STATUS.fldAllperc,TBL_REQUEST_STATUS.fldAllRemarks FROM
TBL_REQUEST_APPROVAL RIGHT JOIN (TBL_WORKFLOW_APPROVAL RIGHT JOIN TBL_REQUEST_STATUS ON TBL_WORKFLOW_APPROVAL.fldTrackNo = TBL_REQUEST_STATUS.fldTrackNo) ON TBL_REQUEST_APPROVAL.fldTrackNo = TBL_REQUEST_STATUS.fldTrackNo "
'strSQL = strSQL & "TBL_WORKFLOW_APPROVAL.fldDivApproved FROM TBL_WORKFLOW_APPROVAL RIGHT JOIN TBL_REQUEST_STATUS ON TBL_WORKFLOW_APPROVAL.fldTrackNo = TBL_REQUEST_STATUS.fldTrackNo "
If IsCADOPR2(gNetID) Then
Forms![FRM_MAIN]![subForm]![subForm3].Form.RecordSource = strSQL & " WHERE (TBL_REQUEST_STATUS.fldAllStatus <> 'Completed' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Cancelled' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Unprocessed')
AND (fldCADopr = '" & gNetID & "' OR fldCAD1 = '" & gNetID & "' OR fldCAD2 = '" & gNetID & "' OR fldCAD3 = '" & gNetID & "' OR fldCAD4 = '" & gNetID & "') ORDER BY TBL_REQUEST_STATUS.fldDateInitiated DESC" 'OR fldReqBy = '" & gNetID & "') AND fldUnitName = '" & gUnitDesc & "'"
ElseIf IsEDUMember(gNetID) Then
If Trim(DLookup("fldPosLevel", "TBL_USER", "fldNetID = '" & Trim (gNetID) & "'")) = "DRAFTSMAN" Then
Forms![FRM_MAIN]![subForm]![subForm3].Form.RecordSource = strSQL & " WHERE TBL_WORKFLOW_APPROVAL.fldAssignedEngr = '" & gNetID & "' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Completed' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Cancelled' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Unprocessed' ORDER BY TBL_REQUEST_STATUS.fldDateInitiated DESC"
Else
Forms![FRM_MAIN]![subForm]![subForm3].Form.RecordSource = strSQL & " WHERE TBL_REQUEST_STATUS.fldAllStatus <> 'Completed' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Cancelled' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Unprocessed' ORDER BY TBL_REQUEST_STATUS.fldDateInitiated DESC"
End If
Else
Forms![FRM_MAIN]![subForm]![subForm3].Form.RecordSource = strSQL & " WHERE fldUnitName = '" & gUnitDesc & "' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Completed' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Cancelled' AND
TBL_REQUEST_STATUS.fldAllStatus <> 'Unprocessed' ORDER BY TBL_REQUEST_STATUS.fldDateInitiated DESC"
End If
End If
setUpAccessLevel
End Sub
On Clicking the Submit it will be saved in the SQL database but it throw the error message.
As a general rule, anytime you going to run reports, query additional data, you would do BEYOND well to FIRST save the current record in the current context. In addition, if this is a new record, then un-like Access tables, the default values, and PK generation does NOT occur until such time you saved the current record.
so, in you code, you want to safe tuck away the current record. This will allow SQL server to setup the PK values and any default columns. So
Private Sub cmdPostSubmit_Click()
postSubmit = 1
postOnly = 0
If me.Dirty = True then me.Dirty = False ' save current record to table.
The other issue is does your code work for existing records, and not new ones, or does it always error out?
I'm trying to set command buttons to enter data into a table. If the record already exists I want the button to update it, and if it does not the button needs to create it. Here's a sample of what the table looks like
ID scenarioID reductionID Impact Variable Variable Impact
1 1 1 Safety 4
2 1 1 Environmental 2
3 1 1 Financial 1
In order to accurately locate records, it needs to search for the specific impact variable paired with the scenarioID. I'm trying to use a select statement, but DoCmd.RunSQL doesn't work for select statements, and I'm not sure how else to do it.
Here's the code. I left DoCmd.SQL in front of the select statement for lack of anything else to place there for now.
Private Sub Var1R1_Click() 'Stores appropriate values in tImpact upon click
'Declaring database and setting recordset
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tImpact")
'Declaring Variable as Scenario Choice combobox value
Dim Sc As Integer
Sc = Schoice.Value
'Stores impact variable
Dim impvar1 As String
'Desired impact variable for column 1
impvar1 = DLookup("impactVariable", "tImpactVars", "ID = 1")
DoCmd.RunSQL "SELECT * FROM tImpact WHERE [Impact Variable] = " & impvar1 & " AND scenarioID = " & Sc
If rs.EOF Then
DoCmd.RunSQL "INSERT INTO tImpact(scenarioID, [Impact Variable], [Variable Impact])" & "VALUES (" & Sc & ", " & impvar1 & ", 1)"
MsgBox "Record Added", vbOKOnly
Else
db.Execute "UPDATE tImpact SET [Variable Impact] = 1 WHERE [Impact Variable] = " & impvar1 & " AND scenarioID = " & Sc
MsgBox "Record Updated", vbOKOnly
End If
End Sub
If anyone can tell me how to get that SELECT statement to run, or another way of doing this, that would be great.
Any help is greatly appreciated!
You can use a recordset. In this case a recordset is better, since you only execute the SQL one time, if it returns a record, you "edit" and if not then you "add" with the SAME reocrdset. This approach is FAR less code, and the values you set into the reocrdset does not require messy quotes or delimiters etc.
eg:
scenaridID = 1 ' set this to any number
impvar1 = "Safety" ' set this to any string
updateTo = "Financial"
strSQL = "select * from tImpact where [Impact Variable] = '" & impvar1 & "'" & _
" AND scenaridID = " & scenaridID
Set rst = CurrentDb.OpenRecordset(strSQL)
With rst
If .RecordCount = 0 Then
' add the reocrd
.AddNew
Else
.Edit
End If
!scenaridID = scenarid
![Impact Variable] = impvar1
![Variable Impact] = 1
.Update
End With
rst.Close
So you can use the same code for the update and the edit. It just a question if you add or edit.
Use OpenRecordset and retrieve the ID for the record if it exists.
Private Sub Command0_Click()
Dim aLookup(1 To 3) As String
Dim aAction(1 To 3) As String
Dim rs As Recordset
Dim db As Database
'Replace these two constants with where you get the information on your form
Const sIMPVAR As String = "Financial"
Const lSCENID As Long = 1
'Build the SQL to find the ID if it exists
aLookup(1) = "SELECT ID FROM tImpact"
aLookup(2) = "WHERE ScenarioID = " & lSCENID
aLookup(3) = "AND ImpactVariable = """ & sIMPVAR & """"
'Run the sql to find the id
Set db = CurrentDb
Set rs = db.OpenRecordset(Join(aLookup, Space(1)))
If rs.BOF And rs.EOF Then 'it doesn't exist, so build the insert statement
aAction(1) = "INSERT INTO tImpact"
aAction(2) = "(ScenarioID, ImpactVariable, VariableImpact)"
aAction(3) = "VALUES (" & lSCENID & ", '" & sIMPVAR & "', 1)"
Else 'it does exist, so build the update statement
aAction(1) = "UPDATE tImpact"
aAction(2) = "SET VariableImpact = 1"
aAction(3) = "WHERE ID = " & rs.Fields(0).Value
End If
'Run the action query
db.Execute Join(aAction, Space(1))
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
In Access 2016 I'm trying to open a recordset and save data from it in other variables, but I keep getting this error.
The program itself has more parts, but I only get error in this one, it just update data on its database.
This is my code:
Option Compare Database
Option Explicit
Private Sub btnValidateTimesheet_Click()
' Update timesheet to "Justificat"
Dim intIdTimesheet As Integer
If IsNull(cmbDraftTimesheets.Value) Then
MsgBox("You have to select a timesheet that is Borrador")
Exit Sub
End If
intIdTimesheet = cmbDraftTimesheets.Column(0)
DoCmd.SetWarnings False
DoCmd.RunSQL "update Timesheets set estat = ""Justificat"" where id=" & intIdTimesheet
DoCmd.SetWarnings True
End Sub
Private Sub btnValidateTimesheetLines_Click()
' We select the timesheet_lines for employee, project, activity and dates selected
' For each justification, a new "Justificat" Timesheet is generated which hang timesheet_lines
' ------------------------------- Variables -------------------------------
Dim dictTsLines As Object
Set dictTsLines = CreateObject("Scripting.Dictionary")
' Form inputs
Dim intCodTreb As Integer
Dim strCodProj As String
Dim dateInici, dateFi As Date
Dim intExercici As Integer
' Query strings
Dim strSQLFrom, strSQLWhere As String
Dim strSQLCount, strSQLJustAct, strSQLTsLines As String
' Recordsets
Dim rsCount, rsJustAct, rsTimesheets, rsTsLines As Recordset
' Aux and others...
Dim continue As Integer
Dim intIdJustificacio, intIdTs As Integer
Dim strActivitat As String
' --------------------------------------- Main ---------------------------------------------
' Taking form data
intCodTreb = cmbTreballador.Column(0)
strCodProj = cmbProjecte.Column(1)
dateInici = txtDataInici.Value
dateFi = txtDataFi.Value
' We check the dates are correct
If IsNull(dateInici) Or IsNull(dateFi) Then
MsgBox("Dates can't be null")
Exit Sub
End If
If dateFi < dateInici Then
MsgBox("Start date must be earlier or the same as final date")
Exit Sub
End If
If year(dateInici) <> year(dateFi) Then
MsgBox("Dates must be in the same year")
Exit Sub
End If
intExercici = year(dateInici)
' Make of the clause FROM and WHERE of the select query of timesheet_lines
strSQLFrom = " from (timesheet_lines tsl " & _
" left join timesheets ts on tsl.timesheet_id = ts.id) " & _
" left join justificacions j on j.id = ts.id_justificacio "
strSQLWhere = " where ts.estat = ""Borrador"" " & _
" and tsl.data >= #" & Format(dateInici, "yyyy/mm/dd") & "# " & _
" and tsl.data <= #" & Format(dateFi, "yyyy/mm/dd") & "# "
If Not IsNull(intCodTreb) Then
strSQLWhere = strSQLWhere & " and tsl.cod_treb = " & intCodTreb
End If
If Not IsNull(strCodProj) Then
strSQLWhere = strSQLWhere & " and j.cod_proj=""" & strCodProj & """ "
End If
' Alert how much timesheet_lines are going to be validated
strSQLCount = "select count(*) " & strSQLFrom & strSQLWhere
Set rsCount = CurrentDb.OpenRecordset(strSQLCount)
Continue Do = MsgBox( rsCount(0) & " registries are going to be validated" & vbNewLine & _
"Do you want to continue?", vbOKCancel)
If continue <> 1 Then
Exit Sub
End If
' We select the tuples Justificacio, Activitat of timesheet_lines selected
strSQLJustAct = "select distinct ts.id_justificacio " & strSQLFrom & strSQLWhere
Set rsJustAct = CurrentDb.OpenRecordset(strSQLJustAct)
Set rsTimesheets = CurrentDb.OpenRecordset("Timesheets")
' A new timesheet is generated for each tupla
Do While Not rsJustAct.EOF
intIdJustificacio = rsJustAct(0)
strActivitat = rsJustAct(1)
rsTimesheets.AddNew
rsTimesheets!data_generacio = Now()
rsTimesheets!estat = "Justificat"
rsTimesheets!Id_justificacio = intIdJustificacio
rsTimesheets!activitat = strActivitat
rsTimesheets!data_inici = dateInici
rsTimesheets!data_fi = dateFi
rsTimesheets!exercici = intExercici
intIdTs = rsTimesheets!Id
rsTimesheets.Update
' We save the related id of the selected timesheet in a dictionary
dictTsLines.Add intIdJustificacio & "_" & strActivitat, intIdTs
rsJustAct.MoveNext
Loop
' We select all the affected timesheet_lines and we update the related timesheet using the dictionary
strSQLTsLines = "select tsl.id, tsl.timesheet_id, ts.id_justificacio, ts.activitat " & strSQLFrom & strSQLWhere
Set rsTsLines = CurrentDb.OpenRecordset(strSQLTsLines)
With rsTsLines
Do While Not .EOF
.EDIT
intIdJustificacio = !Id_justificacio
strActivitat = !activitat
!timesheet_id = dictTsLines.Item(intIdJustificacio & "_" & strActivitat)
.Update
.MoveNext
Loop
End With
rsTimesheets.Close
Set rsCount = Nothing
Set rsJustAct = Nothing
Set rsTimesheets = Nothing
Set rsTsLines = Nothing
End Sub
Debugger: The error is coming up at the line:
strActivitat = rsJustAct(1)
I checked that the data the recordset is saving exists and it does.
Your recordset contains just one column ("select distinct ts.id_justificacio"), but you are trying to read second column strActivitat = rsJustAct(1)
Add requred column to recordset.
Dim mydb As DAO.Database
Dim myrst As DAO.Recordset
Dim Date1, Date2 As Date
Dim mysql As String
Dim qdf As QueryDef
Dim EmployeeID As String
EmployeeID = DLookup("lngEmpID", "tblEmployees", "Forms!frmEmployeeOrderForm.cboEmployeeName.Value = EmployeeName")
Me.EmpID = EmployeeID
PickupTime = DLookup("Pickup", "tblEmployees", "Forms!frmEmployeeOrderForm.cboEmployeeName.Value = EmployeeName")
Me.PickupDay = PickupTime
Set mydb = CurrentDb
Date1 = Me.dtmGiveAwayDate1
Date2 = Me.dtmGiveAwayDate2
mysql = ("Select tblOrders.lngEmpID, tblOrders.dtmGiveAwayDate1, tblOrders.dtmGiveAwayDate2 FROM tblOrders WHERE tblOrders.lngEmpID =" & EmployeeID & " AND tblOrders.dtmGiveAwayDate1 =" & Date1 & " AND tblOrders.dtmGiveAwayDate2 =" & Date2)
MsgBox mysql
Set myrst = mydb.OpenRecordset(mysql)
If myrst.EOF = False Then
MsgBox "You have already ordered for this PFG." & vbCrLf & "Please see Jody for help."
cmdCancel_Click
Exit Sub
End If
When I run the program I am trying to prevent employees from entering their name twice for the same dates. To test I tried to duplicate a record for the same employee and it will not trigger the myrst.eof = false and display the message box that says "You have already ordered for this PFG". Any help is much appreciated.
Thank you in advance.
Use the FindFirst method :
myrst.FindFirst "field = " & value
If myrst.NoMatch Then
//code when record doesn't exist
End If
Checking for equality with dates can be tricky. Since VBA dates can include time to the nanosecond, could it be that one side (SQL/code) has a real time, while the other has the default midnight value?
Set mydb = CurrentDb
Date1 = Format(Me.dtmGiveAwayDate1, "Short Date")
Date2 = Format(Me.dtmGiveAwayDate2, "Short Date")
mysql = ("Select tblOrders.lngEmpID, tblOrders.dtmGiveAwayDate1, tblOrders.dtmGiveAwayDate2 FROM tblOrders WHERE tblOrders.lngEmpID =" & EmployeeID & " AND tblOrders.dtmGiveAwayDate1 =" & "#" & Date1 & "#" & " AND tblOrders.dtmGiveAwayDate2 =" & "#" & Date2 & "#")
MsgBox mysql
Set myrst = mydb.OpenRecordset(mysql)
This was the code I used and it works now. Thank you.
I have a gridview that fills with data, and a view button which gives more details of the record choosen by the user. I cannot figure out why I am getting the error:
Object reference not set to a instance of an Object
I have narrowed it down to between my two message boxes. The First message box comes up but it crashes before the second. Any suggestions would be greatly appreciated.
Protected Sub CountAlerts_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles CountAlerts.RowCommand
If (e.CommandName = "Viewdtails") Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim NDC, Unit, Cell, DTTM, prod, Query, _startdt, _enddt As String
Dim DS As DataSet
NDC = CountAlerts.DataKeys(index).Values("NDC")
Cell = CountAlerts.DataKeys(index).Values("Cell")
Unit = CountAlerts.DataKeys(index).Values("Unit")
DTTM = CountAlerts.DataKeys(index).Values("TimeDate")
prod = CountAlerts.DataKeys(index).Values("ProductDesc")
_startdt = If(StartDate.Text = "", DateAdd(DateInterval.Day, -7, System.DateTime.Now).ToShortDateString, StartDate.Text)
_enddt = If(EndDate.Text = "", System.DateTime.Now.ToShortDateString, EndDate.Text)
For Each irow As GridViewRow In CycleCountAlerts.Rows
If irow.Attributes("class") = "highlight" Then
irow.Attributes.Remove("class")
End If
Next
CountAlerts.Rows(index).Attributes("class") = "highlight"
Query = " EXEC [Audits].[dbo].[ExceptionDetailsCombined] '" & NDC & "', '" & Cell & "', '" & Unit & "', '" & DTTM & "', '" & Master.CF_User.Viewing & "' "
DS = SelectQuery(Query)
If (DS.Tables.Count > 0) Then
unitbox.Text = DS.Tables(0).Rows(0)("Unit")
cellbx.Text = DS.Tables(0).Rows(0)("Cell")
ndcbox.Text = DS.Tables(0).Rows(0)("NDC")
namebox.Text = DS.Tables(0).Rows(0)("ProductDesc")
cycdttmbx.Text = DS.Tables(0).Rows(0)("TimeDate")
cycusr.Text = DS.Tables(0).Rows(0)("CycUser")
todisp.Text = DS.Tables(0).Rows(0)("TODISPSIZE")
topkgbox.Text = DS.Tables(0).Rows(0)("TOPKGSIZE")
toqtybx.Text = DS.Tables(0).Rows(0)("TOQTY")
FRQTYbx.Text = DS.Tables(0).Rows(0)("FRQTY")
TextBox2.Text = DS.Tables(0).Rows(0)("ActualQTY")
cycvarqbox.Text = DS.Tables(0).Rows(0)("CYCLEVARQTY")
CycleVarPctbx.Text = DS.Tables(0).Rows(0)("CYCLEVARPCT")
alertrsnbx.Text = DS.Tables(0).Rows(0)("AlertReason")
combox.Text = DS.Tables(0).Rows(0)("AcceptComment")
acusr.Text = DS.Tables(0).Rows(0)("AcceptUser")
acctime.Text = DS.Tables(0).Rows(0)("AcceptTime")
accstatbx.Text = DS.Tables(0).Rows(0)("AcceptStatus")
displbl.Text = DS.Tables(0).Rows(0)("Disposition")
End If
Query = " EXEC [CF_Audits].[dbo].[CommentTrackerCombined] '" & Master.CF_User.EmployeeID & "', '" & NDC & "', '" & Cell & "', '" & Unit & "', '" & _startdt & "', '" & _enddt & "', '" & Master.CF_User.Viewing & "' "
DS = SelectQuery(Query)
If (DS.Tables.Count > 0) Then
ExceptionHist_GV.DataSource = DS
ExceptionHist_GV.DataBind()
ExceptionHist_GV.UseAccessibleHeader = True
MsgBox("except gv header") 'Runs up to here.
ExceptionHist_GV.HeaderRow.TableSection = TableRowSection.TableHeader
MsgBox("except gv header 2") ' Does not make it to here.
End If
End If
End Sub
Most likely TableRowSection or TableRowSection.TableHeader is/are Nothing
Check that these are initialised before using them
If MsgBox("except gv header")
If Not TableRowSection Is Nothing AndAlso Not TableRowSection.TableHeader Is Nothing Then
ExceptionHist_GV.HeaderRow.TableSection = TableRowSection.TableHeader
Else
MsgBox "How did we get here?"
End If
MsgBox("except gv header 2")
If you see the message "How did we get here" that indicates you have not initialised you object
In object orientated languages you need to instantiate an object before you can use it.
Something in this line:
ExceptionHist_GV.HeaderRow.TableSection = TableRowSection.TableHeader
has not been instantiated with the new keyword. You can find out exactly what by checking the details of the Exception which was thrown.
It will be either ExceptionHist_GV or TableRowSection.