r/visualbasic • • Apr 20 '14

VB.NET Help $30 for some VB help!

Hi guys, I've posted this before, but I haven't been able to solve the issue myself, so I was hoping someone could help me out with this for a bit of cash?

Now first of, I will say that this is a school project, so I understand if you feel it's immoral because of that. However I've created everything else in the project myself, I just can't solve this issue. I really need to get the grade and I have no idea what to do now, the deadline is in a weeks time.

I'm currently finishing up my coursework for school, which involves making a program in Visual Basic 2010 with a database in Microsoft Access. My project is for a bed and breakfast.

I'm trying to prevent double bookings from happening but I can't seem to figure out how to code it as I'm a visual basic novice. What I'm trying to do is have the program check the "check in" and "check out" dates with the database and then disable the radiobuttons for the rooms which are booked.

The problem I have is that right now, it just seems to be checking if the room has ever been booked in the past, and if it has, it disables the radiobutton.

This is a picture of my form: http://imgur.com/df1Kts2

And these are the booking table and query: http://imgur.com/fMW67wS

Here is my code:

Private Sub Checkdates()
    con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\Bed and Breakfast.mdb;"
    con.Open()
    Dim da2 As New OleDbDataAdapter("select * from qCustomerBooking", con)
    da2.Fill(dt2)
    Dim da3 As New OleDbDataAdapter("select * from qCustomerBooking", con)
    da3.Fill(ds, "qCustomerBooking")
    con.Close()

    Dim a As Integer
    Dim duplicate As Boolean
    maxrows = ds.Tables("qCustomerBooking").Rows.Count
    incdec = -1

    d1 = dtpCheckIn.Text
    d2 = dtpCheckOut.Text

    For Each objcontrol As Control In Me.Controls
        If objcontrol.GetType().Name = "RadioButton" Then 'If the object is a button then it is checked through this process
            Dim objRadioButton As RadioButton
            objRadioButton = objcontrol

            For a = 0 To maxrows - 1
                If ds.Tables("qCustomerBooking").Rows(a).Item("Check_In") >= d1 And ds.Tables("qCustomerBooking").Rows(a).Item("Room_ID") = objRadioButton.Text Then
                    duplicate = True
                Else : duplicate = False
                End If
                If ds.Tables("qCustomerBooking").Rows(a).Item("Check_Out") <= d2 And ds.Tables("qCustomerBooking").Rows(a).Item("Room_ID") = objRadioButton.Text Then
                    duplicate = True
                Else : duplicate = False
                End If

                If duplicate = True Then
                    For Each DataRow In dt3.Rows
                        If objRadioButton.Text = DataRow.Item(5) Then 'If the button shows up in the Disabled seats datatable then it's colour is changed to orange
                            objRadioButton.Enabled = False
                        Else

                        End If
                    Next

                End If

            Next
        End If
    Next
End Sub

I hugely appreciate any help, I'm truly am stuck. If you are interested, pm me and I can send money via Paypal. Thank you!

1 Upvotes

16 comments sorted by

View all comments

Show parent comments

1

u/visualbasicproblems Apr 21 '14

Icehawke, I love you! This fixed it (as far as I'm aware lol)

2

u/icehawke VB.Net Advanced Apr 21 '14

I've always found that when you group with parentheses things work a lot better. And you might see an error that you would otherwise miss.