Solved

Append to a Litbox

Posted on 2007-11-18
4
481 Views
Last Modified: 2013-11-27
Hi,

I have two forms: frmScanTags and frmScanTagPop

frmScanTags has a listbox lbScannedtags.  frmScanTagPop acts like a popup for which is opened above the frmScanTags table and allows the user to enter a tag number in the single field on this form.

What i am trying to do is what ever tag is entered into the frmScanTagPop form is checked to see if it excits in tblAssignedTags and if so is apended to the listbox in the frmScanTags form.

It would be like querying tblAssignedTags with the data which is entered in the popup form and adding the results to the listbox

Hope someone can help me find a way to achieve this.

Anthony
0
Comment
Question by:d10u4v
  • 3
4 Comments
 
LVL 26

Expert Comment

by:Alan Warren
Comment Utility
Hi Anthony,
it sounds like you are almost there.
If your popup form is correctly adding tags all you need to do is requery the listbox on the form that invoked the popup.

So in your code that invokes the popup, after the openForm command.
    lbScannedtags.requery


hth

Alan



0
 

Author Comment

by:d10u4v
Comment Utility
That's the problem, its not adding tags, that is what i'm trying to achieve. :(
Anthony
0
 
LVL 26

Expert Comment

by:Alan Warren
Comment Utility
Hi Anthony,

Not really sure how your are invoking your popup form (frmScanTagPop)
but I would do it like this:

I would append and Item to listbox --Add tag--
You can do this by modifying the recordsource for the listbox
eg:
SELECT tblAssignedTags.ID, tblAssignedTags.tag FROM tblAssignedTags; Union All Select 0, "--Add tag--"  FROM tblAssignedTags Where ID = 1

Then you can add a AfterUpdate Event procedure to the the listbox, to invoke your popup form (frmScanTagPop)
like so:

With me so far?

Alan


Private Sub lbScannedtags_AfterUpdate()

 If lbScannedtags.Column(0) = 0 Then

   'Open your popup form

   DoCmd.OpenForm "frmScanTagPop", acNormal, , , acFormAdd, acDialog

 End If

 

 lbScannedtags.Requery
 

End Sub

Open in new window

0
 
LVL 26

Accepted Solution

by:
Alan Warren earned 500 total points
Comment Utility
Hi Anthony,
sorry stopped for dinner, lol.

Anyway after you get the first part working you need to add some code to the popup forms before update event, to check if the the new tag they are trying to enter already exists and if it does, cancel the update.
Like so:

Private Sub Form_BeforeUpdate(Cancel As Integer)
 

    ' Make sure the tag field is not null or empty string

    If Nz(Me.txtTag, 0) <> 0 And Me.txtTag <> "" Then

        ' Build the filter criteria

        Dim strWhere As String

        strWhere = "Tag='" & Me.txtTag & "'"

         

         ' Count the recods in the table matching the criteria

         If DCount("ID", "tblAssignedTags", strWhere) Then

           MsgBox ("Already have tag for " & txtTag)

           Cancel = True

           DoCmd.Close acForm, Me.Name, acSaveNo

         End If

        

    End If
 

End Sub

Open in new window

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now