If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Code to Determine if records exist in an Unbound List Box
I have and unbound form with an unbound List Box that has a query as the
record source. I use the following code to update the List Box and then determine if there are records and take the apporpriate action. Unfortunately, if I put the code Forms![Post GASP Data].Controls("ListComputerID").ListIndex = 0 after the first "SetFocus" statement when no records exist, it errors out. If I don't use this statement when records do exist, it just goes to the first IF statement option and exits the function. How can I re-write this code to look in the List Box for records and then take the appropriate action? DoCmd.SetWarnings False 'This step imports new PC GASP Audit records into the 'the "GASP Audit - Server Details" table. DoCmd.OpenQuery "Append - Computer Data" 'This call the referenced Function to update the Computer Data records Call UpdateGASPAuditData 'This requeries the form and sets focus to the form. Forms![Post GASP Data]![ListComputerID].Requery Forms![Post GASP Data]![ListComputerID].SetFocus 'This checks for Nul record set and exits fucntion if true If (IsNull(Forms![Post GASP Data]![ListComputerID])) Then MsgBox "No New Computer Data to add to the GASP Database.", vbInformation, "GASP Database" Exit Function Else 'This sets forcus to the first record Forms![Post GASP Data].Controls("ListComputerID").ListIndex = 0 'This calls the referenced function to append the software records Call AppendGASPComputerApplications End If MsgBox "The New Computer Data has been added to the GASP Database.", vbInformation, "GASP Database" DoCmd.SetWarnings True |
#2
|
|||
|
|||
Code to Determine if records exist in an Unbound List Box
"Chris" wrote in message
... I have and unbound form with an unbound List Box that has a query as the record source. I use the following code to update the List Box and then determine if there are records and take the apporpriate action. Unfortunately, if I put the code Forms![Post GASP Data].Controls("ListComputerID").ListIndex = 0 after the first "SetFocus" statement when no records exist, it errors out. If I don't use this statement when records do exist, it just goes to the first IF statement option and exits the function. How can I re-write this code to look in the List Box for records and then take the appropriate action? DoCmd.SetWarnings False 'This step imports new PC GASP Audit records into the 'the "GASP Audit - Server Details" table. DoCmd.OpenQuery "Append - Computer Data" 'This call the referenced Function to update the Computer Data records Call UpdateGASPAuditData 'This requeries the form and sets focus to the form. Forms![Post GASP Data]![ListComputerID].Requery Forms![Post GASP Data]![ListComputerID].SetFocus 'This checks for Nul record set and exits fucntion if true If (IsNull(Forms![Post GASP Data]![ListComputerID])) Then MsgBox "No New Computer Data to add to the GASP Database.", vbInformation, "GASP Database" Exit Function Else 'This sets forcus to the first record Forms![Post GASP Data].Controls("ListComputerID").ListIndex = 0 'This calls the referenced function to append the software records Call AppendGASPComputerApplications End If MsgBox "The New Computer Data has been added to the GASP Database.", vbInformation, "GASP Database" DoCmd.SetWarnings True If I understand you correctly, change this: If (IsNull(Forms![Post GASP Data]![ListComputerID])) Then .... to this: If Forms![Post GASP Data]!ListComputerID.ListCount 0 Then Is this code in the code module of the form [Post GASP Data] ? If so, you could replace all occurrences of "Forms![Post GASP Data]" with "Me", the keyword that refers to the object containing the executing code. -- Dirk Goldgar, MS Access MVP Access tips: www.datagnostics.com/tips.html (please reply to the newsgroup) |
#3
|
|||
|
|||
Code to Determine if records exist in an Unbound List Box
Thanks for the reply, I stumbled upon that after posting this question. Here
is what I added after the SetFocus statement If Forms![Post GASP Data].Controls("ListComputerID").ListCount 0 Then 'This sets forcus to the first record Forms![Post GASP Data].Controls("ListComputerID").ListIndex = 0 End If An the code is not in the form. |
Thread Tools | |
Display Modes | |
|
|