Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2011
    Posts
    26

    Unanswered: Openargs date question

    Hello All,

    I have read only form that has information about a person's visit on a particular date and am trying to create a button that would allow me to open up a similar form with the same data, but in an edit mode. The information on the editable form would be pulled up using an openargs statement, but I am having a little trouble with it. When I click the button, the desired form opens, but the correct data isn't brought up. Here is my code. Any help would be greatly appreciated.

    read only form

    Code:
    Private Sub Command78_Click()
       DoCmd.OpenForm "editvisit", acNormal, , , acFormEdit, , PERSONID.Value & ";" & VISIT_DATE.Value
       DoCmd.Close acForm, "visit"
    End Sub
    editable form

    Code:
    Private Sub Form_Load()
     If Not IsNull(Me.OpenArgs) Then
    lngpersonid = Left(OpenArgs, InStr(OpenArgs, ";") - 1)
    dtevisitdate = CDate(Mid(OpenArgs, InStr(OpenArgs, ";") + 1))
    Me.PERSONID.DefaultValue = lngmrn
    Me.VISIT_DATE.DefaultValue = Format(dtevisitdate, "\#mm\/dd\/yyyy\#")
    End If
    End Sub

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    From your description, you want something more like this:

    Open a second form to the record

    Your code is going to pull up the form with the first record in its data source, which presumably isn't the one you want.
    Paul

  3. #3
    Join Date
    Jun 2011
    Posts
    26
    Yes, that's the exact problem I would have. I would always open up the second form to the first record of the specified personid, but not their correct visit date. If I want to include two where conditions would I separate them by using & ";" &?

    Thanks in advance

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    No, you'd use AND. If one is a number and the other is a date

    Code:
    DoCmd.OpenForm "SecondFormName", , , "FieldName = " & Me.ControlName & " AND SecondFieldName = #" & Me.SecondControlName & "#"
    Paul

  5. #5
    Join Date
    Jun 2011
    Posts
    26
    Hi pbaldy, thanks for all your help so far, but I've run into some trouble and I don't know how to solve the problem. I've created the code using the example you gave me:

    Private Sub Command78_Click()
    Dim linkpersonid As Variant
    Dim linkdate As Date
    linkpersonid = "personid=" & Me.PERSONID
    linkdate = "VISIT_DATE = #" & Me.VISIT_DATE & "#"
    DoCmd.OpenForm "editvisit", , , linkpersonid And linkdate, acFormEdit
    DoCmd.Close acForm, "visit"
    End Sub
    When I run this, I get a type 13 mismatch error. The yellow error bar is over the linkdate line. I changed the linkdate from date to varient to see what happens, and then the error moves to the following line. I think it has something to do with how linkdate is defined as when I put my curesr over me.visit_date, the desired date is shown, but when I put it over linkdate, 12:00:00 AM is show. The fix is probably simple, but I am lost. Thanks again.

  6. #6
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    You have to concatenate the AND into the string that you're building. Try:

    linkpersonid & " And " & linkdate
    Paul

  7. #7
    Join Date
    Jun 2011
    Posts
    26
    Awesome, I added what you suggested and changed "date" to "variant" and it works. Thanks for your help, it's appreciated.

  8. #8
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Happy to help!
    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •