Results 1 to 9 of 9
  1. #1
    4 Star Lounger
    Join Date
    Oct 2002
    Location
    Sayre, Pennsylvania, USA
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding Code Criteria (2000)

    Hi,
    I have the following code below and it works great. Basically I click on a button and it goes to another form and only shows data that matches my combo boxes. I would like to add code that also checks to see if another field is empty (txtRefNoDoc). If it's empty I would like a msgbox to display saying they have to fill in that field first BEFORE they go on and then have the cursor move to the txtRefNoDoc field waiting for input. Any ideas?

    Private Sub cmdCreateCoverPage_Click()
    On Error GoTo Err_Command151_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmContractCoverPage"

    stLinkCriteria = "[lngMachineID]=" & Me![cboPRDPLSelect]
    stLinkCriteria = "[lngVendorID]=" & Me![cboPRVendorSelect]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_Command151_Click:
    Exit Sub

    Err_Command151_Click:
    MsgBox Err.Description
    Resume Exit_Command151_Click

    End Sub


    Thanks,
    Deb

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Adding Code Criteria (2000)

    This code is strange:

    stLinkCriteria = "[lngMachineID]=" & Me![cboPRDPLSelect]
    stLinkCriteria = "[lngVendorID]=" & Me![cboPRVendorSelect]

    The result of the first line is completely undone by the second line, so you might as well omit the first line, unless you meant to combine the two criteria. In that case, you should use one line:

    stLinkCriteria = "[lngMachineID]=" & Me![cboPRDPLSelect] & " AND [lngVendorID]=" & Me![cboPRVendorSelect]

    To build in a check, use something like this:

    If IsNull(Me.txtRefNoDoc) Then
    MsgBox "Please enter a value.", vbExclamation
    Me.txtRefNoDoc.SetFocus
    Exit Sub
    End If

    Insert these lines after the declarations (Dim ...).

  3. #3
    4 Star Lounger
    Join Date
    Oct 2002
    Location
    Sayre, Pennsylvania, USA
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding Code Criteria (2000)

    Thanks Hans,
    I did want to include both criteria. I thought the same thing about one canceling the other but don't know enough about coding and it seemed to work. Thanks for fixing that. Also, the other addition works with the exception of I get the below error message and it highlights the SetFocus text.

    "Compile Error:
    Method or data member not found."

    I changed the line to this: Me!txtRefNoDoc.SetFocus and when I click on the button I get the msgbox but then I click on OK and I get this message: "Object doesn't support this property or method. Any thoughts?

    Thanks,
    Deb

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Adding Code Criteria (2000)

    Are you sure that txtRefNoDoc is the exact name of a text box on the form that contains cmdCreateCoverPage? Watch out carefully for spelling errors.

  5. #5
    4 Star Lounger
    Join Date
    Oct 2002
    Location
    Sayre, Pennsylvania, USA
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding Code Criteria (2000)

    That was it, the name txtRefNoDoc was spelled correct but on further inspection for some reason in the Name property it had tblPurchaseRequest.txtRefNoDoc, so I took out the table and it works great. THANKS!

    Another question if you don't mind. When I click on the cmdCreateCoverPage button it goes to another form that individuals have to fill out some more fields. Some of these fields I have default data that I'd like to show, but whenever I put in the criteria: stLinkCriteria = "[lngMachineID]=" & Me![cboPRDPLSelect] & " AND [lngVendorID]=" & Me![cboPRVendorSelect], my default values will not show up in the fields. If I take out that link criteria and just go to the form (new record) the default values show up. It's like I have to have one or the other, link criteria or new record. I do notice that when I use link criteria it has Filtered by the record navigation buttons which I'm assuming is my problem. But is there a work around?

    I want the link criteria because some data is carried over into other fields, but I would also like my default data so the user doesn't have to type all that in.

    Thanks,
    Deb

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Adding Code Criteria (2000)

    Opening a form with a where-condition (link criteria) should have no influence on the default values for fields, unless perhaps those default values are set in code (for example in the On Open or On Load event of the form.)

    That your form displays (Filtered) next to the record count is natural, that is what the where-condition does: filter the records displayed in the form. It shouldn't cause problems.

  7. #7
    4 Star Lounger
    Join Date
    Oct 2002
    Location
    Sayre, Pennsylvania, USA
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding Code Criteria (2000)

    Hans,
    Sorry it took me so long to respond, I was on vacation. The default data is not in code, it's in the properties of the field in the default item, it's just typed in, most of it is just text, addresses that will stay the same and such. Any ideas as to what else could be causing it to not show?
    thanks,
    Deb

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Adding Code Criteria (2000)

    I'm sorry, I have no idea what could be causing this. As usual, you can post a stripped down version of the database if you like.

  9. #9
    4 Star Lounger
    Join Date
    Oct 2002
    Location
    Sayre, Pennsylvania, USA
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding Code Criteria (2000)

    Thanks for responding. It was nice to know that it should show default values so I did a bunch of checking and bascially I had put the default values just on the form fields, I added them at the table level and everything works great! Thanks a ton for your help.
    Deb
    <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

Posting Permissions

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