Column Appointment Time Cannot be found VB

Discussion in 'Programming/Html' started by Alexis444, Nov 23, 2016.

  1. Alexis444

    Alexis444 Member Guru

    Messages:
    192
    Likes Received:
    1
    GPU:
    XFX RX 5700XT RAW
    Hey guys! Hope everyone is doing great!

    As the tittle says, I am finishing a project, which is a medical registry patients for a hospice. I have a table named Appointments and this table has a column named Appointment Time Which handles the date and time of the appointments. The column was designed with the date/time feature in access. I am trying to get a color change in the rows with the date, like, if the appointment date has passed, changes to red and if still not passed stays white. Did some reseach and came out with this code:

    Private Sub Appointments_DataBindingComplete(sender As System.Object, e As System.Windows.Forms.DataGridViewBindingCompleteEventArgs) Handles AppointmentsDataGridView.DataBindingComplete
    For i = 0 To AppointmentsDataGridView.Rows.Count - 4
    Dim expDate As Date = AppointmentsDataGridView.Rows(i).Cells("Appointment Time").Value
    If DateDiff(DateInterval.Month, Date.Now, expDate) <= 0 Then
    AppointmentsDataGridView.Rows(i).DefaultCellStyle.BackColor = Color.Red
    Else
    AppointmentsDataGridView.Rows(i).DefaultCellStyle.BackColor = Color.White
    End If
    Next
    End Sub

    Everytime I run the debugger comes out with the error Column Appointment Time Cannot be found. Any one can see what I'm doing wrong
     
  2. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,541
    Likes Received:
    13,561
    GPU:
    GF RTX 4070
    Try to enclose "Appointment Time" in "[]" - "[Appointment Time]".
     
  3. Alexis444

    Alexis444 Member Guru

    Messages:
    192
    Likes Received:
    1
    GPU:
    XFX RX 5700XT RAW
    I tried But came out with the same error. What I did was change the Appointment Time which is the name of the column to the number of the column. It worked but is highlighting the entire row instead of the column.

    What I actually wants is to hightlight in red the appointments that has passed and the other that not stay in white.
     
  4. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,541
    Likes Received:
    13,561
    GPU:
    GF RTX 4070
    Thats because you switch the background on whole row:
    and you want the cell
     

Share This Page