Page 1 of 2 12 LastLast
Results 1 to 15 of 20

Thread: Opening Forms

  1. #1
    Join Date
    Jul 2003
    Posts
    292

    Unanswered: Opening Forms

    I have a search form with a button that pulls any specific record in..

    Now the thing is.. each of these records can have sub-records to them... I want to build an additional button on my search form that says something like "add sub-record" and when the user clicks on the button certain fields from original record goes into a new form .. that way the user will know that the sub-record they are about to enter is going to that orginal record....

    I was thinking.. have the code behind button "add sub-record" when clicked open form SUB-REcord then plot data from original record.. then have user fill out the rest of the fields for that sub-record..

    how do you open the new form and plot data of oringal record ? I'm fairly new so if you could explain with detail that would be greatly appreciated.

    THanks

  2. #2
    Join Date
    Sep 2003
    Location
    T.O.
    Posts
    326
    There are many techniques to accomplish what you are trying to do. What I most often use is the OpenArgs property of a form delimited by semi-colons (when semi-colons are not a subset of the data).

    Button on main form uses DoCmd.OpenForm FormName:=YourFormName, OpenArgs:=Create Your Data Here.

    The Open method of the subform checks for the OpenArgs, if not isnull(Me.OpenArgs), then decompile the delimited string with the Function Split or iteratively use Instr and Mid.

    Because you control the OpenArgs from the DoCmd.OpenForm, you always know what order they are in, thus you can set the values on the new form.
    All code ADO/ADOX unless otherwise specified.
    Mike.

  3. #3
    Join Date
    Jul 2003
    Posts
    292
    Thanks Mike.. I'll give this a try..

  4. #4
    Join Date
    Jul 2003
    Posts
    292

    Angry

    I keep on getting an error ... compile error : invalid qualifier... on my second form..

    my 2nd form is called.. "frmAddInspec" with 3 text fields "Text1,Text2.Text3" all string

    My first form.. the values that I want over on my second form are..
    "Project,Area,Reference"

    My code behind the cmd button of first form is..

    Code:
    Private Sub Command11_Click()
    DoCmd.OpenForm "frmAddInspec", OpenArgs:=Project & ";" & Area & ";" & Reference
    
    End Sub
    My code for my second form.. in the open event handler is...

    Code:
    Private Sub Form_Open(Cancel As Integer)
    Dim Project As String
    Dim Area As String
    Dim Reference As String
    Dim Iloc1 As Integer
    Dim iLoc2 As String
    Dim strArgs As String
    Dim Text1, Text2, Text3 As String
    
    strArgs = Me.OpenArgs & ""
    
    If Len(strArgs) > 0 Then
     Iloc1 = InStr(strArgs, ";")
     If Iloc1 > 0 Then
        Project = Left$(strArgs, Iloc1 - 1)
        Text1.Text = Project
        iLoc2 = InStr(Iloc1 + 1, strArgs, ";")
        Area = Mid$(strArgs, Iloc1 + 1, iLoc2 - Iloc1 - 1)
        Text2.Text = Area
        Reference = Mid$(strArgs, iLoc2 + 1)
        Text3.Text = Reference                        //////////////// error here
     End If
    End If
    End Sub

    Any ideas what I'm doing wrong..


    Thanks

  5. #5
    Join Date
    Sep 2003
    Location
    T.O.
    Posts
    326
    Try changing your variables names by prepending them with the type of variable they are. For ex strReference instead of Reference. My guess is that because 'Reference' is an Access reserved word, it's getting confused as to what you want to do.

    On a separate note, to avoid the math behind InStr and Mid (I'm sure it's working for you, I personally don't like adding and subtracting as I always get it wrong the first time), you may want to look at the Split function. It's kinda neat.
    All code ADO/ADOX unless otherwise specified.
    Mike.

  6. #6
    Join Date
    Jul 2003
    Posts
    292
    I dont understand it... I'm still getting the same error.. and its pointing to the same spot...

  7. #7
    Join Date
    Apr 2003
    Posts
    280
    try this:

    docmd.OpenForm "Form_frmAddInspec"

  8. #8
    Join Date
    Jul 2003
    Posts
    292
    I did this

    Code:
    Private Sub Command11_Click()
    DoCmd.OpenForm "Form_frmAddInspec", OpenArgs:=strProject & ";" & strArea & ";" & strReference
    
    End Sub

    and got an error.. it states that it can't find the form.. or the form doesnt exist.. I know for certain the form is there.. I just double check.. it is there and that is how i spelt it to..

  9. #9
    Join Date
    Sep 2003
    Location
    T.O.
    Posts
    326
    Usu when you make named references, if you specify one, you specify 'em all, i.e.,

    Private Sub Command11_Click()
    DoCmd.OpenForm FormName:="Form_frmAddInspec", OpenArgs:=strProject & ";" & strArea & ";" & strReference

    End Sub

    Either that or you use absolute references and omit paramters if you don't need 'em, i.e.,

    DoCmd.OpenForm "Form_frmAddInspec", , , , , , strProject & ";" & strArea & ";" & strReference
    All code ADO/ADOX unless otherwise specified.
    Mike.

  10. #10
    Join Date
    Jul 2003
    Posts
    292
    mike,

    I tired something else.. I tired to reference the fields.. by putting me.text1..etc.. I get a different error.. I dont know if I'm fixing or making the problem worst..

    thanks

    --------------------------------------------------------

    run-time error 2185
    You can't reference a property or method for a control unless the control has the focus..

    -------------------------------------------------------

    Code:
    Private Sub Form_Open(Cancel As Integer)
    Dim strProject As String
    Dim strArea As String
    Dim strReference As String
    Dim Iloc1 As Integer
    Dim iLoc2 As String
    Dim strArgs As String
    Dim Text1, Text2, Text3 As String
    
    strArgs = Me.OpenArgs & ""
    
    If Len(strArgs) > 0 Then
        Iloc1 = InStr(strArgs, ";")
        If Iloc1 > 0 Then
            strProject = Left$(strArgs, Iloc1 - 1)
            Me.Text1.Text = strProject
            iLoc2 = InStr(Iloc1 + 1, strArgs, ";")
            strArea = Mid$(strArgs, Iloc1 + 1, iLoc2 - Iloc1 - 1)
            Me.Text2.Text = strArea
            strReference = Mid$(strArgs, iLoc2 + 1)
            MsgBox strReference  ' testing only
            Me.Text3.Text = strReference
        End If
    End If
    End Sub
    mike,

    also the code you gave me above.. still gives me the same error.. both of them.. thanks

  11. #11
    Join Date
    Sep 2003
    Location
    T.O.
    Posts
    326
    Can you zip and post the db? I'll take a look at it for you. If there is proprietary data in there, you can either jumble or get rid of it. This should strictly be a VBA issue, but keep the table structure intact.
    All code ADO/ADOX unless otherwise specified.
    Mike.

  12. #12
    Join Date
    Jul 2003
    Posts
    292
    sure mike I can .zip it up... thanks so much for your time...

    the form that I'm trying to get to work now is.. frmsearch "addinspec" button


    thanks again mike

  13. #13
    Join Date
    Jul 2003
    Posts
    292
    can you see the file mike ? I added it on but i dont see it.. let me kn0w .. i'll send it to your e-mail or something..

    thanks

  14. #14
    Join Date
    Apr 2003
    Posts
    280
    Originally posted by TonyT
    I did this

    Code:
    Private Sub Command11_Click()
    DoCmd.OpenForm "Form_frmAddInspec", OpenArgs:=strProject & ";" & strArea & ";" & strReference
    
    End Sub

    and got an error.. it states that it can't find the form.. or the form doesnt exist.. I know for certain the form is there.. I just double check.. it is there and that is how i spelt it to..
    Try opening the form without the arguments after the commas, to see if it open up. I just did a sample form, you do'nt need the word Form in front of frmAddInspec. Just Docmd.OpenForm "frmAddInspec"
    Last edited by lansing; 09-17-03 at 13:47.

  15. #15
    Join Date
    Apr 2003
    Posts
    280
    Originally posted by TonyT
    mike,

    I tired something else.. I tired to reference the fields.. by putting me.text1..etc.. I get a different error.. I dont know if I'm fixing or making the problem worst..

    thanks

    --------------------------------------------------------

    run-time error 2185
    You can't reference a property or method for a control unless the control has the focus..

    -------------------------------------------------------

    just set YOURTextNAME.setfocus before reference to the texbox

Posting Permissions

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