Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    jheintz57 is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    28

    If statements directing to different forms and populating field

    I have this script below which is supposed to open on form if "[solid_waste?]" is true and another if false. Both forms might not have a record in the required table yet and I need to be able to put the Manifest_ID into each if that is the case. Access is saying their is a data type mismatch but won't show me where so I need some help.

    Thanks

    Private Sub Command24_Click()

    On Error GoTo Err_Command24_Click
    Dim stForm As String
    Dim stDocName As String
    Dim stTable As String
    Dim stID As String
    Dim stLinkCriteria As String
    Dim intCounter As Integer

    If Me.[solid_waste?] = True Then

    stForm = "frm_RCRA" And stTable = "tbl_RCRA" And stID = "RCRA_ID"

    Else

    stForm = "frm_DOT" And stTable = "tbl_DOT" And stID = "DOT_ID"

    End If

    intCounter = IIf(IsNull(DCount("[stID]", "stTable", "[manifest_id]=" & Me.Manifest_ID)), 0, DCount("[stID]", "stTable", "[manifest_id]=" & Me.Manifest_ID))
    Select Case intCounter
    Case Is = 0
    DoCmd.OpenForm "stForm", , , , acFormAdd


    Forms!stForm!Manifest_ID = Me.Manifest_ID
    Case Is >= 1

    stDocName = "stForm"

    stLinkCriteria = "[manifest_id]=" & Me![manfiest_ID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    End Select
    Exit_Command24_Click:
    Exit Sub

    Err_Command24_Click:
    MsgBox Err.Description
    Resume Exit_Command24_Click

    End Sub

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I'll get you started but you may have other issues. Try:
    stForm = "stTable = 'tbl_RCRA' And stID = " & RCRA_ID
    This is just a guess.

  3. #3
    jheintz57 is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    28
    Are there missing" etc in the line you types or should I replace the entire
    stForm = "frm_RCRA" And stTable = "tbl_RCRA" And stID = "RCRA_ID"

    with

    stForm = "stTable = 'tbl_RCRA' And stID = " & RCRA_ID

    ??




  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Replace the entire line to start with. There are *no* missing quotes in the line I supplied.

  5. #5
    jheintz57 is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    28
    There are 2 different forms. What you typed wouldn't open one form instead of the other.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    What are the names of both forms - exactly please.

  7. #7
    jheintz57 is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    28
    they are in the script above
    "frm_RCRA" and "frm_DOT"

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    In which case all you need is:
    Code:
    If Me.[solid_waste?] = True Then
       stForm = "frm_RCRA" 
    Else
       stForm = "frm_DOT" 
    End If
    ...and:
    Code:
    DoCmd.OpenForm stForm, , , , acFormAdd

  9. #9
    jheintz57 is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    28
    Yes, that takes care of the opening different forms but the challenge I am having is the bottom part of the code...if there isn't already a record in the table (ie tbl_RCRA) that is connected to the record of the previous form, I need the manifest_ID to populate the soon-to-be-created new record in the form (ie in the frm_RCRA). And if there is already a record I need it to open to it.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Paul wrote this one just for me and you: http://www.baldyweb.com/OpenArgs.htm

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I'm gone for the rest of the afternoon so I'll check back in tonight to see how you made out.

  12. #12
    jheintz57 is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    28
    I have been playing with that code and the openargs really only works if you select a record in the previous form. I am not selecting a record from a list or anything, merely carrying the manifest_id from the previous form over to the next form...it is not an id that will change in the first form.

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You lost me. You can fill the OpenArgs arguments any way you want.

  14. #14
    jheintz57 is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    28
    Yeah, I see that now. and I got it for the first part...where there isn't already a record in the table to makes up the second form. Now I am having a problem with the second part...where the Case IS >=1...there is a record...right now this code opens it to a completely blank record.

    Private Sub Manifest_Continue_Click()

    Dim stForm As String
    Dim stDocName As String
    Dim stTable As String
    Dim stID As String
    Dim intCounter As Integer


    If Me.[solid_waste?] = True Then

    stForm = "frm_RCRA"
    stTable = "tbl_RCRA_inventory"
    stID = "RCRA_ID"

    Else

    stForm = "frm_DOT"
    stTable = "tbl_DOT_inventory"
    stID = "DOT_ID"

    End If


    intCounter = IIf(IsNull(DCount(stID, stTable, "[Manifest_id]=" & Me.Manifest_ID)), 0, DCount(stID, stTable, "[Manifest_id]=" & Me.Manifest_ID))

    Select Case intCounter

    Case Is = 0
    DoCmd.OpenForm stForm, , , , , acFormAdd, Me.Manifest_ID


    Case Is >= 1
    DoCmd.OpenForm stForm, , , [Manifest_ID] = " & Me![Manifest_ID]"

    End Select

    Exit_select_site_Click:
    Exit Sub

    End Sub


    It may be a problem with my receiving form which right how has a code on the formload:

    Private Sub Form_Load()
    If Me.OpenArgs <> vbNullString Then
    Me.Manifest_ID = Me.OpenArgs
    End If
    End Sub

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Your receiving form code should be:
    Code:
    Private Sub Form_Load()
    If Not IsNull(Me.OpenArgs) Then
       Me.Manifest_ID = Me.OpenArgs
    End If
    End Sub

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Auto Populating a field in a table
    By softspoken in forum Access
    Replies: 11
    Last Post: 04-05-2010, 02:52 PM
  2. Populating a "Text" field in a Report
    By two_smooth in forum Reports
    Replies: 20
    Last Post: 02-19-2010, 11:25 AM
  3. IIF Statements
    By JDA2005 in forum Queries
    Replies: 8
    Last Post: 07-07-2009, 04:24 PM
  4. If statements
    By Ezeecopy in forum Access
    Replies: 0
    Last Post: 03-24-2009, 04:54 AM
  5. Populating Data in forms
    By cjbeck71081 in forum Forms
    Replies: 4
    Last Post: 01-16-2007, 04:15 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums