• Creator
    Topic
  • #4273
    sfritz
    Participant

    Hi,

    Two questions. I am launching my form using showmodal, and when the user clicks the submit button I run form validation routine that checks fields for appropriate entries and use exit sub and setting the modal result for the form to MRNONE to allow the user to make changes, seems to work ok however I need to set the modal result to MROK once the processing is complete to close the form. Is this the best way? (Code at bottom)

    My second question is in regards to using either the Dateimepicker or TRDateTimeEdit, I am having problems writing the appropriate date or time information out to my database (MYSQL). If I use the TRDatetimeEdit and assign the variable the .text value it writes out the proper value for the date but its not a true date. Is the numeric value in julian format and if so how do I control it to write out MDY? I do not see any formatting options. I am having no success with the time portion. My only other thought is that I have to break out the date and time portion and format with code manually. Any guidance would be appreciated.

    Thanks,
    sfritz

    — Code —
    Sub Main(Client, GWEvent)
    dim userid
    MYFORM.showmodal
    End Sub

    Sub Add_Record
    dim iRST
    dim fname
    dim lname
    dim userid

    userid = groupwise.EnvUserID
    fname = MYFORM.fname.text
    lname = MYFORM.lname.text
    address = MYFORM.Address.text
    dc = MYFORM.Date_of_call.text
    tc = MYFORM.Time_Call.time

    Set iADOObj = CreateObject(“ADODB.Connection”)
    if isobject(iADOObj) then

    ‘ open the test data source with the Connection object
    iConnnectString = “Driver={MySQL ODBC 3.51 Driver}; Data Source=MySQL”
    iADOObj.Open iConnnectString

    ‘ Are we connected?
    if err.number = 0 then
    iSQLString = “Insert into names (date_of_call,time_of_call,firstname, lastname) values(‘” & dc & “‘,'” & tc & “‘,'” & fname & “‘,'” & lname & “‘” & “)”

    Set iRST = iADOObj.Execute(iSQLString)
    iADOObj.Close
    end if
    else
    call msgbox(“Failed to create ADODB.Connection object.”, vbCritical, CAPTION)
    end if
    Set iADOObj = Nothing
    MYFORM.ModalResult = MROK
    End Sub

    Sub SubmitBtnClick(Sender)
    dim x, Sectioninfo, sidx, iCheckedItems

    for x = 0 to MYFORM.initial_contact.Items.count -1
    if MYFORM.initial_contact.ItemChecked(x) then
    iCheckedItems = iCheckedItems & MYFORM.initial_contact.items.strings(x) & vbcrlf
    end if
    next

    if iCheckedItems = “” then
    msgbox(“You must select the method of initial contact .”)
    MYFORM.ModalResult = MRNONE
    exit sub
    end if

    Add_Record
    End Sub

  • Author
    Replies
  • #7682
    Support 1
    Participant

    Thank you for your enquiry.

    I am not sure what you mean by “the best way” to (if I understand your question) use a form’s ModalResult property. If you look at the list of values for this property in the Object Inspector (open the drop-down list), I believe all of them except for mrNone will close the form.

    Suppose you have a form with multiple buttons (OK, Cancel).

    • If you want to do some validation when the user clicks OK, then at design time set the ModalResult property of the OK button to mrNone (as in your example). Your validation routine (eg. an event handler for the OK button) should not need to set the form’s ModalResult unless the input is valid, ie. ModalResult = mrOK. (If the form is displayed more than once you might need to reinitialize ModalResult to mrNone.)
    • No validation should be necessary for Cancel, so this button’s ModalResult property should be mrCancel, so the form will close automatically.

    Suppose your applet has two forms, FormA and FormB, and that FormA shows FormB. You can choose the possible ModalResult values for FormB (or the buttons on FormB) to suit the needs of FormA. The following code shows an example:

      dim iChoice
    
      iChoice = FormB.ShowModal
      if iChoice = mrYes then
        ' do something for Yes option...
      elseif iChoice = mrNo then
        ' do something for No option...
      elseif iChoice = mrCancel then
        ' cancel the process
      end if
    

    The choice between DateTimePicker and RzDateTimeEdit is largely aesthetic. I would choose the one that seems easiest for users. See the online Help files for these controls; RzDateTimeEdit offers some additional functionality that may simplify your work.

    To format the date value, you can use the VBScript functions:

      iText = FormatDateTime(DateTimePicker1.Date, vbShortDate)
      msgbox iText
    
      iYear = Year(DateTimePicker1.Date)
      iMonth = Month(DateTimePicker1.Date)
      iDay = Day(DateTimePicker1.Date)
      iText = iMonth & "/" & iYear & "/" & iDay
      msgbox iText

    See the VBScript online Help for details.

    I hope this helps.

    Regards,
    Advansys Support

    [This message was edited by Support 1 on July 12, 2006 at 07:08 PM.]

    #7683
    sfritz
    Participant

    Thank you for your help. Using this same example, if I would like to prompt the user if they would like to add another record, would this be done using another form? I would like the data entry from be closed, the user prompted to add another record, if yes then show the form again, if not return to groupwise. I do not want many versions of the data entry for open.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.