Results 1 to 3 of 3

Thread: Display sub

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780

    Display sub

    i have the following code to display the records that i have selected.
    VB Code:
    1. '*****************************************************
    2. 'Display the fields for this specific record in the
    3. 'text boxes. The added spaces are for null values
    4. 'this sub performs dual function
    5. 'if mode = 0 then it searches
    6. 'if mode = 1 it simply displays the current record
    7. Private Sub Display(theMode As Integer)
    8. 'Call clear
    9. Dim found As Boolean
    10.     If theMode = 0 Then
    11.         rs.MoveFirst
    12.         If ToolID = "" Then
    13.             txtNum.Text = rs!ToolNumber
    14.             txtDrNum.Text = rs![Drawing Number] & ""
    15.             cmbTType.Text = rs![Type of tool] & ""
    16.             txtDie.Text = rs![Die Type] & ""
    17.             txtDate.Text = rs![Date Created] & ""
    18.             cmbVend.Text = rs!Vendor & ""
    19.             cmbDepart.Text = rs!Department & ""
    20.             txtAssign.Text = rs![Tool Number assigned by] & ""
    21.             txtSketch.Text = rs!PSketch & ""
    22.             txtStore.Text = rs![Storage Location] & ""
    23.             txtPMType.Text = rs!PMType & ""
    24.             cmbStatus.Text = rs!status & ""
    25.             txtDesc.Text = rs!Description & ""
    26.            
    27.         Else
    28.             Do While (Not rs.EOF) And (Not found)
    29.                 If rs(0) <> ToolID Then
    30.                     rs.MoveNext
    31.                     found = False
    32.                 Else
    33.                     found = True
    34.                     txtNum.Text = rs!ToolNumber
    35.                     txtDrNum.Text = rs![Drawing Number] & ""
    36.                     cmbTType.Text = rs![Type of tool] & ""
    37.                     txtDie.Text = rs![Die Type] & ""
    38.                     txtDate.Text = rs![Date Created] & ""
    39.                     cmbVend.Text = rs!Vendor & ""
    40.                     cmbDepart.Text = rs!Department & ""
    41.                     txtAssign.Text = rs![Tool Number assigned by] & ""
    42.                     txtSketch.Text = rs!PSketch & ""
    43.                     txtStore.Text = rs![Storage Location] & ""
    44.                     txtPMType.Text = rs!PMType & ""
    45.                     cmbStatus.Text = rs!status & ""
    46.                     txtDesc.Text = rs!Description & ""
    47.  
    48.                 End If
    49.             Loop
    50.         If Not found Then
    51.             txtNum.Text = rs!ToolNumber
    52.             txtDrNum.Text = rs![Drawing Number] & ""
    53.             cmbTType.Text = rs![Type of tool] & ""
    54.             txtDie.Text = rs![Die Type] & ""
    55.             txtDate.Text = rs![Date Created] & ""
    56.             cmbVend.Text = rs!Vendor & ""
    57.             cmbDepart.Text = rs!Department & ""
    58.             txtAssign.Text = rs![Tool Number assigned by] & ""
    59.             txtSketch.Text = rs!PSketch & ""
    60.             txtStore.Text = rs![Storage Location] & ""
    61.             txtPMType.Text = rs!PMType & ""
    62.             cmbStatus.Text = rs!status & ""
    63.             txtDesc.Text = rs!Description & ""
    64.  
    65.         End If
    66.     End If
    67. ElseIf theMode = 1 Then
    68.             If rs.BOF Or rs.EOF Then
    69.                 MsgBox "No Record found for that number!", , "RECORD NOT FOUND"
    70.                 If MsgBox("Would you like to add this record?", vbYesNo, "Add Record?") = vbYes Then
    71.                     Me.Show
    72.                     Call clear
    73.                     txtNum.Text = ToolID
    74.                     txtNum.Locked = True
    75.                     'cmbDepart.SetFocus
    76.                     changes = False
    77.                 Else
    78.                     rs.MoveFirst
    79.                     GoTo KeepGoing
    80.                 End If
    81.             Else
    82. KeepGoing:
    83.                 Me.Show
    84.                 txtNum.Text = rs!ToolNumber
    85.                 txtDrNum.Text = rs![Drawing Number] & ""
    86.                 cmbTType.Text = rs![Type of tool] & ""
    87.                 txtDie.Text = rs![Die Type] & ""
    88.                 txtDate.Text = rs![Date Created] & ""
    89.                 cmbVend.Text = rs!Vendor & ""
    90.                 cmbDepart.Text = rs!Department & ""
    91.                 txtAssign.Text = rs![Tool Number assigned by] & ""
    92.                 txtSketch.Text = rs!PSketch & ""
    93.                 txtStore.Text = rs![Storage Location] & ""
    94.                 txtPMType.Text = rs!PMType & ""
    95.                 cmbStatus.Text = rs!status & ""
    96.                 txtDesc.Text = rs!Description & ""
    97.             End If
    98. End If
    99. Call MachList
    100. changes = False
    101. End Sub
    i have a problem when it comes to this spot
    VB Code:
    1. ElseIf theMode = 1 Then
    2.             If rs.BOF Or rs.EOF Then
    3.                 MsgBox "No Record found for that number!", , "RECORD NOT FOUND"
    4.                 If MsgBox("Would you like to add this record?", vbYesNo, "Add Record?") = vbYes Then
    5.                     Me.Show
    6.                     Call clear
    7.                     txtNum.Text = ToolID
    8.                     txtNum.Locked = True
    9.                     'cmbDepart.SetFocus
    10.                     changes = False
    11.                 Else
    12.                     rs.MoveFirst
    13.                     GoTo KeepGoing
    14.                 End If
    15.             Else
    16. KeepGoing:
    17.                 Me.Show
    18.                 txtNum.Text = rs!ToolNumber
    19.                 txtDrNum.Text = rs![Drawing Number] & ""
    20.                 cmbTType.Text = rs![Type of tool] & ""
    21.                 txtDie.Text = rs![Die Type] & ""
    22.                 txtDate.Text = rs![Date Created] & ""
    23.                 cmbVend.Text = rs!Vendor & ""
    24.                 cmbDepart.Text = rs!Department & ""
    25.                 txtAssign.Text = rs![Tool Number assigned by] & ""
    26.                 txtSketch.Text = rs!PSketch & ""
    27.                 txtStore.Text = rs![Storage Location] & ""
    28.                 txtPMType.Text = rs!PMType & ""
    29.                 cmbStatus.Text = rs!status & ""
    30.                 txtDesc.Text = rs!Description & ""
    31.             End If
    i'm trying to not do any thing there. the program crashes when the user clicks no. i'm not sure how to make the program to not do any thing.
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Display sub

    Originally posted by Dubya007
    VB Code:
    1. '*****************************************************
    2. 'Display the fields for this specific record in the
    3. 'text boxes. The added spaces are for null values
    4. 'this sub performs dual function
    5. 'if mode = 0 then it searches
    6. 'if mode = 1 it simply displays the current record
    7. Private Sub Display(theMode As Integer)
    8. 'Call clear
    9. Dim found As Boolean
    10.     If theMode = 0 Then
    11.         rs.MoveFirst
    12.         If ToolID = "" Then
    13.             txtNum.Text = rs!ToolNumber
    14.             txtDrNum.Text = rs![Drawing Number] & ""
    15.             cmbTType.Text = rs![Type of tool] & ""
    16.             txtDie.Text = rs![Die Type] & ""
    17.             txtDate.Text = rs![Date Created] & ""
    18.             cmbVend.Text = rs!Vendor & ""
    19.             cmbDepart.Text = rs!Department & ""
    20.             txtAssign.Text = rs![Tool Number assigned by] & ""
    21.             txtSketch.Text = rs!PSketch & ""
    22.             txtStore.Text = rs![Storage Location] & ""
    23.             txtPMType.Text = rs!PMType & ""
    24.             cmbStatus.Text = rs!status & ""
    25.             txtDesc.Text = rs!Description & ""
    26.            
    27.         Else
    28.             Do While (Not rs.EOF) And (Not found)
    29.                 If rs(0) <> ToolID Then
    30.                     rs.MoveNext
    31.                     found = False
    32.                 Else
    33.                     found = True
    34.                     txtNum.Text = rs!ToolNumber
    35.                     txtDrNum.Text = rs![Drawing Number] & ""
    36.                     cmbTType.Text = rs![Type of tool] & ""
    37.                     txtDie.Text = rs![Die Type] & ""
    38.                     txtDate.Text = rs![Date Created] & ""
    39.                     cmbVend.Text = rs!Vendor & ""
    40.                     cmbDepart.Text = rs!Department & ""
    41.                     txtAssign.Text = rs![Tool Number assigned by] & ""
    42.                     txtSketch.Text = rs!PSketch & ""
    43.                     txtStore.Text = rs![Storage Location] & ""
    44.                     txtPMType.Text = rs!PMType & ""
    45.                     cmbStatus.Text = rs!status & ""
    46.                     txtDesc.Text = rs!Description & ""
    47.  
    48.                 End If
    49.             Loop
    50.         If Not found Then
    51.             txtNum.Text = rs!ToolNumber
    52.             txtDrNum.Text = rs![Drawing Number] & ""
    53.             cmbTType.Text = rs![Type of tool] & ""
    54.             txtDie.Text = rs![Die Type] & ""
    55.             txtDate.Text = rs![Date Created] & ""
    56.             cmbVend.Text = rs!Vendor & ""
    57.             cmbDepart.Text = rs!Department & ""
    58.             txtAssign.Text = rs![Tool Number assigned by] & ""
    59.             txtSketch.Text = rs!PSketch & ""
    60.             txtStore.Text = rs![Storage Location] & ""
    61.             txtPMType.Text = rs!PMType & ""
    62.             cmbStatus.Text = rs!status & ""
    63.             txtDesc.Text = rs!Description & ""
    64.  
    65.         End If
    66.     End If
    67. ElseIf theMode = 1 Then
    68.             If rs.BOF Or rs.EOF Then
    69.                 MsgBox "No Record found for that number!", , "RECORD NOT FOUND"
    70.                 If MsgBox("Would you like to add this record?", vbYesNo, "Add Record?") = vbYes Then
    71.                     Me.Show
    72.                     Call clear
    73.                     txtNum.Text = ToolID
    74.                     txtNum.Locked = True
    75.                     'cmbDepart.SetFocus
    76.                     changes = False
    77.                 Else
    78.                     rs.MoveFirst
    79.                     GoTo KeepGoing
    80.                 End If
    81.             Else
    82. KeepGoing:
    83.                 Me.Show
    84.                 txtNum.Text = rs!ToolNumber
    85.                 txtDrNum.Text = rs![Drawing Number] & ""
    86.                 cmbTType.Text = rs![Type of tool] & ""
    87.                 txtDie.Text = rs![Die Type] & ""
    88.                 txtDate.Text = rs![Date Created] & ""
    89.                 cmbVend.Text = rs!Vendor & ""
    90.                 cmbDepart.Text = rs!Department & ""
    91.                 txtAssign.Text = rs![Tool Number assigned by] & ""
    92.                 txtSketch.Text = rs!PSketch & ""
    93.                 txtStore.Text = rs![Storage Location] & ""
    94.                 txtPMType.Text = rs!PMType & ""
    95.                 cmbStatus.Text = rs!status & ""
    96.                 txtDesc.Text = rs!Description & ""
    97.             End If
    98. End If
    99. Call MachList
    100. changes = False
    101. End Sub
    Well its a good idea to condense the code unfortunately its not a good idea to use the goto line as you have. In fact I don't recall a good use for goto except in error handling... and then its developers preference anyway.

    Let me see if this is what you want.

    Mode=0
    loop through each record (is this bound??) until the tool id matchs
    Mode=1
    get the details of the selected record to view and do so.

    Is rs the recordset already there?
    Would it be easier to reset rs to a recordset filtered on the toolid specified (searching)?

    Sorry if I'm no help...
    Sounds like you are pretty close to what you want though.


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    yeah i actually got it and am now working on a whole set of new problems in my program. thnax for looking though.
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

Posting Permissions

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



Click Here to Expand Forum to Full Width