locked
Need Help (Newbie) RRS feed

  • Question

  • hi,

    can anyone help me in my program, im new to vb and i've been searching codes to creat this. my program is event management and so far i have two forms my 1st form is main

    Private Sub calendar_DateSelected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles calendar.DateSelected
    
            t = calendar.SelectionRange.Start.Month.ToString & calendar.SelectionRange.Start.Day.ToString
    
            Try
    
                If File.Exists(t) = True Then
                    add.Show()
    
                Else
    
                    m = MsgBox("Would you like to enter events for this date?", MsgBoxStyle.YesNo)
                    If m = MsgBoxResult.Yes Then
                        add.Show()
    
                    End If
                End If
    
            Catch ex As Exception
                MsgBox(ex.Message)
    
            End Try
        End Sub
    
    

    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'Valley_of_GraceDataSet.all_event' table. You can move, or remove it, as needed.'
            Me.All_eventTableAdapter.Fill(Me.Valley_of_GraceDataSet.all_event)
    
            Dim m1 As MsgBoxResult
            t = calendar.SelectionRange.Start.Month.ToString & calendar.SelectionRange.Start.Day.ToString
    
            If Date.Today = calendar.TodayDate And File.Exists(t) = True Then
                m1 = MsgBox("You have events set for today. Would you like to view them?", MsgBoxStyle.YesNo)
    
                If m1 = MsgBoxResult.Yes Then
                    add.Show()
    
                End If
    
    
            End If
        End Sub
    there's my code on the calendar and main load above

    and when u click on the date the add form will appear.

    this form dont have any functions yet. now my problem is i want to set the default value of of 'Date'(date time picker) depends on the date clicked on the calendar.

    and please teach me how to save its content into database(access2007?) what i want is when i click on save the value of all those in that form will be saved on a blank access file name Valley of Grace Vision Church.accdb/mdb i really dont know where to start. im new here and only studying this online. thank you. i just need this program for my thesis thank you for your time. =)

    Wednesday, February 8, 2012 2:05 PM

Answers

  • The first line of code above (Dim addForm As New....) would be in the main form, not the add class.  I presume that the calendar is on that form.

    The Sub New would be created in the add class.  To get around the error, just add the InitializeComponent() call as the first line in the sub New.

    Public Sub New(ByVal apptDate As DateTime)
        InitializeComponent()
    
        Me.dtpDate.Value = apptDate
    End Sub

    Be sure to change dtpDate to whatever the name of your control is.

    EDIT:  I created a simple example.  Here is the code.

    I created a new project and added two forms:  Main and Add.

    On the form Main, I added a MonthCalender control and a single button.  I named the MonthCalender "Calendar".

    On the Add form, I added a DateTimePicker control.  Below is the code behind for both forms:

    Main form:

    Public Class Main
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgsHandles Button1.Click
            Dim addForm As New Add(Me.Calendar.SelectionStart)
            addForm.ShowDialog()
        End Sub
    End Class
    

    Add form:

    Public Class Add
        Public Sub New(apptDate As DateTime)
            InitializeComponent()
     
            Me.ApptDate.Value = apptDate
        End Sub
    End Class

    When you run the program, select a date on the MonthCalender and click the button.  The button will create a new instance of the Add form, passing in the selected date, and then show the form.

    Hopefully this makes what I first posted clearer.

    • Edited by Chris Dunaway Wednesday, February 15, 2012 7:36 PM
    • Marked as answer by Jhude Thursday, February 16, 2012 10:12 AM
    Wednesday, February 15, 2012 7:23 PM

All replies

  • Probably the easiest method is to pass the selected date into the add form in the constructor (Sub New).  Then populate the DateTimePicker from that. 

    For example, inside the add form you would have something like this (change the name of the controls to whatever you have used on your form):

    Public Sub New(apptDate As DateTime)
        Me.DateTimePickerControl.Value = apptDate
    End Sub

    Then, when you create the add form, you would pass in the selected date:

    Dim addForm As New add(calendar.SelectedRange.Start) addForm.ShowDialog()

    Again, be sure to use the correct names for the forms/controls.  This is only example code.

    I hope this helps!

    Chris

    Thursday, February 9, 2012 5:49 PM
  • Hi Jhude,

    Welcome to the MSDN forum.

    In my opinion, this program is not a good start for a newcomer. 

    I’d like to give some suggestions about saving data and using database. A database is used to store and management data. Before start with this program, we need to make sure how many data needs to use and save into database. We need to analysis all the data and create the tables in database (to store data). And then, create the project. 

    >>  what i want is when i click on save the value of all those in that form will be saved on a blank access file name Valley of Grace Vision Church.accdb/mdb i really dont know where to start.

    So there is some issue with your design. We needn’t save all the data in the form to the database, because some data in the form is useless to store it.  For your project, you only need to save the data in datagridview. At the same time, the database is not empty; you need create the table in it firstly.

    Before finish this project, I’m afraid that you need to learn something about database, hope it helps.

    If you have any additional questions, please feel free to let me know.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by horngsh Saturday, February 11, 2012 12:43 PM
    Friday, February 10, 2012 7:13 AM
    Moderator
  • hi mark,

    thank you for your reply. about the database i have found a new way to store data by adding local database i have created table with all the column i need to save, and then all i did is bind them all. however can u teach me the basic code on the save botton, delete and edit. (when saving it i want all the textbox and combobox to be read only, and then when i click on the edit button it will become editable.)

    thankyou for your time mark.



    • Edited by Jhude Saturday, February 11, 2012 9:37 AM
    Saturday, February 11, 2012 9:17 AM
  • You should first learn ADO.Net and apply it in your project.  Please look at this web page at:

    http://msdn.microsoft.com/en-us/library/h43ks021.aspx

    and

    OleDb sample code(for text, csv and accdb and mdb files)

    http://msdn.microsoft.com/en-us/library/dw70f090.aspx#_OleDb


    My blog: http://soho-hsh.blogspot.com

    Saturday, February 11, 2012 12:46 PM
  • Chris,

    sorry i really dont get what you said.

    i've been trying the codes, but i can't call the calendar on my add form. it's always have an error. it is because the calendar is on the main form?

    Sunday, February 12, 2012 4:57 AM
  • Take a look at this sample which is done around what Mike and Shueh suggest you.

    http://www.vb-tips.com/StronglyTypedDataSet.aspx

    http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=23654

    Be aware that although Microsoft advises the Adventure sample databases, there are in my perception created endless versions of that so you never know which one is used.


    Success
    Cor


    Sunday, February 12, 2012 10:48 AM
  • The first line of code above (Dim addForm As New....) would be in the main form, not the add class.  I presume that the calendar is on that form.

    The Sub New would be created in the add class.  To get around the error, just add the InitializeComponent() call as the first line in the sub New.

    Public Sub New(ByVal apptDate As DateTime)
        InitializeComponent()
    
        Me.dtpDate.Value = apptDate
    End Sub

    Be sure to change dtpDate to whatever the name of your control is.

    EDIT:  I created a simple example.  Here is the code.

    I created a new project and added two forms:  Main and Add.

    On the form Main, I added a MonthCalender control and a single button.  I named the MonthCalender "Calendar".

    On the Add form, I added a DateTimePicker control.  Below is the code behind for both forms:

    Main form:

    Public Class Main
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgsHandles Button1.Click
            Dim addForm As New Add(Me.Calendar.SelectionStart)
            addForm.ShowDialog()
        End Sub
    End Class
    

    Add form:

    Public Class Add
        Public Sub New(apptDate As DateTime)
            InitializeComponent()
     
            Me.ApptDate.Value = apptDate
        End Sub
    End Class

    When you run the program, select a date on the MonthCalender and click the button.  The button will create a new instance of the Add form, passing in the selected date, and then show the form.

    Hopefully this makes what I first posted clearer.

    • Edited by Chris Dunaway Wednesday, February 15, 2012 7:36 PM
    • Marked as answer by Jhude Thursday, February 16, 2012 10:12 AM
    Wednesday, February 15, 2012 7:23 PM
  • Sir Chris Dunaway

    THANK YOU VERY VERY MUCH!  i really appreciate your help. thanks a bunch!

    but i have one last question do you know how to filter the datagrid view? im thinking of, the data that will only show in the datagridview depends on the date selected on the dtpDate.

    example if the value of Date is march 20 2012 the data that will only show on the datagrid view is the event that is save on the march 20 2012. also to arrange it ascending based on time start. thank you and sorry for the trouble =)

    Thursday, February 16, 2012 10:22 AM
  • I haven't used data grids much, so I'm afraid I can't help you with that.  Sorry.

    Chris

    Thursday, February 16, 2012 10:23 PM
  • ok sir thanks anyway =)
    Friday, February 17, 2012 12:42 AM