Ok i am going to try to explain this as good as possible.

I got a form, which i plan to use as a calendar/agenda.
I got labels for each week day, these will change each day.
Below each label(day), i got textboxes which are used to enter appointments in(these are saved in a database).

Can i make it so that all these textboxes get cleared for the next week.
So when for example i got appointments set for all week, i can see these as long as we are in the same week.
But when the next week is up on there, the boxes need to be empty.
But i still need to be able to request the information again should it be needed, by going back to previous days.

Being braking my head over this for a while now, but not sure if its even possible.

Dani AI

Generated

Short summary: treat the textboxes as a view onto persistent data rather than permanently clearing stored appointments. Save every appointment with a date/time in the database and, when the form shows a week, query only the rows that fall inside that week. If no row exists for a given day/slot the control will be empty; when navigating back to previous weeks, rerun the same date-range query to repopulate the view.

Suggested table layout and week query: keep a simple appointments table (AppointmentID, UserID, StartDateTime, EndDateTime, Title, Notes, RecurrenceRule, CreatedAt) and index StartDateTime for fast lookups. Use a parameterized date-range query to fetch exactly one week:

-- parameter: @WeekStart (datetime)
SELECT *
FROM Appointments
WHERE StartDateTime >= @WeekStart
  AND StartDateTime < DATEADD(day, 7, @WeekStart)
ORDER BY StartDateTime;

(Use DATEADD to compute the exclusive end bound; docs: https://learn.microsoft.com/en-us/sql/t-sql/functions/dateadd-transact-sql?view=sql-server-ver16)

Compute the week boundaries from a given date (respecting the chosen first day of week). Example helper to get the start-of-week in VB:

Function GetWeekStart(d As DateTime, firstDay As DayOfWeek) As DateTime
    Dim diff As Integer = (7 + (CInt(d.DayOfWeek) - CInt(firstDay))) Mod 7
    Return d.Date.AddDays(-diff)
End Function

Operational notes: use the UI loop/array techniques suggested by and only to clear or initialize the view before binding fresh data. Avoid deleting saved rows—filtering is safer and auditable. Be careful with time zones (store UTC or normalize on save), use an exclusive end bound (< weekStart + 7 days) to avoid overlap, index the datetime column for performance, and handle recurring events by expanding occurrences at query time or storing occurrence records.

Recommended Answers

All 3 Replies

I would imagine the logical place to put the code to clear the textboxes (or repopulate them) is in the same place that determines and displays the labels above those same textboxes. You could place the labels and textboxes in a container (like a groupbox) and use a loop like the following

For Each ctrl as Control in GroupBox1.Controls
    If TypeOf ctrl Is TextBox Then
        Cast(ctrl,TextBox).Text = ""
    End If
Next

Another option would be to create references to the labels and textboxes in arrays such as

Dim labels() As Label   = {lblSunday,lblMonday,lblTuesday...
Dim appts()  As TextBox = {txtSunday,txtMonday,txtTuesday...

Then in your code you could just do

For i as Integer = 0 to 6
    appts(i).Text = ""
Next

You could use a similar loop to generate the correct dates for a given week and updpate the labels using the array.

Alright, gonna give that a try. thanks.

or do a loop through all the textboxes and clear them (or what ever you want to do with them):

For Each t As TextBox In Me.Controls.OfType(Of TextBox)()
	t.Text = String.Empty
Next
commented: "OfType(Of TextBox)" cool. I didn't know that one. +9
commented: i also dont know this quick method .:P thanks +5
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.