Modules & VBA :: Code To Add Data In The Listbox That Meets Certain Criteria?

Jul 17, 2014

I have a Access table that stores BatchNo,Scandate,NewBatchNo . As I can't attach Access database here so I have exported data from Access to Excel in Sheet1 to show how the data is stored in Access table.

Now I have to write code in VBA that will check the last NewBatchNo in the table . In the attached workbook its 194389. Now vba code should check the NewBatchNo which are blank before 194389 . Now in the records where NewBatchNo is blank , it should add the corresponding BatchNo,ScanDate in the listbox1 in form1.

e.g Sheet2 in the attached workbook stores Bathcno and Scandate of those records where NewBatchNo is null and before the Last used NewBatchNo which is 194389 in our example.

View Replies


ADVERTISEMENT

General :: Automatically Delete Data That Meets Criteria?

Mar 15, 2013

I'm an amateur (is there such a thing as having databases as a hobby?) with little training. I volunteered to organize a growing volunteer group I'm a part of by making a simple database for the volunteer office staff. One of the things I want it to do is make name tags for our weekly meetings. I don't want to print one for each name on our list because the list is over 400 names long with only around 35 regular attendees. I made two tables--one is the MakeNameTag table that lists regular attendees (it is a lookup field on the Names table).

The other is the Absences table. It has two fields; DateOfAbsence and MakeNameTag. If someone misses a meeting (does not pick up their name tag), their name is added to the Absences table. A query then filters the table for dates in the last 28 days. If their names shows up four times in the last 28 days I want for their name to be deleted from the MakeNameTag table. How to do that automatically? Our office volunteers have minimal PC skills, so the solution needs to be very user-friendly.

View 3 Replies View Related

Modules & VBA :: Pull Data From A Table That Meets Number Of Conditions?

Jul 3, 2014

I have a module that is in Excel that is connecting to a back end database. I am trying to pull data from a table that meets a number of conditions. With the following statement, it is not returning any records,even though I know there are records that meet all of the conditions. I suspect the problem is with the last condition. In that condition I am trying to say that pull in records where it has been at least 14 days since the last review.

Code:
strSQL = "SELECT tblsojrol_oc.* FROM tblsojrol_oc WHERE tblsojrol_oc.[Status] = 'Pending' AND tblsojrol_oc.[1st Review Date] IS NOT NULL AND " _
& "tblsojrol_oc.[3rd Review Date] IS NULL AND (DateADD(Day,14,tblsojrol_oc.[2nd Review Date])) >= #" & dt & "#;"
objRs.Open strSQL, objConn, adLockReadOnly

View 14 Replies View Related

One Field Meets Criteria Of Another?!?!

Jan 16, 2007

Hi,
I have one field, for this example, FieldA and another FieldB.
I would like the following:
If fieldA =1 then FieldB must = 1 or 3 or 4. If not then I would like a message box saying it needs to check. Otherwise I don't want anything to happen.

How can I do this? and where do I put any expressions?
thanks
Sue

View 7 Replies View Related

Validation Condition Where At Least One Of Four Fields Meets Criteria

Jul 29, 2015

Windows XP
MS Access 2007
VBA experience is very limited

So in my forms 'BeforeUpdate' property I want to validate whether a condition is met. The condition is whether 'any one of 4 fields contains something (text or number)'. I have written this code for validating a single condition and it alerts if the field is left blank. This code returns a warning message when the field is blank.

If Me.[txtObjective] & "" = "" Then
MsgBox "A 'Problem Objective' is required, please complete this field.", vbOKOnly
Me.[txtObjective].SetFocus
Cancel = True

[code]...

how to write the SetFocus part. And I dont know if this is correct anyway.

View 6 Replies View Related

Select Those In A Column That Meets Character Count Criteria

Nov 4, 2005

Hey, I know this is probably a simple thing to do, but I couldn't find it anywhere on the web so hopefully someone here can help.

I have a column of UPC codes which are a bunch of #'s. I need to find the ones that have more than or less than 12 characters.

Thanks

View 2 Replies View Related

Queries :: Identify Subsequent Records Where Original Record Meets A Criteria

Aug 8, 2014

I have a table [PickData] in a WMS (Warehouse Management System) database, that records details of each item picked. The key fields are;

[Movement] - a unique ID for a collection of items to be picked.
[ToAssignRef] - the order ID
[Product] - the product!
[Picked] - the date/time the item was scanned
[Pick Actioned] - the date/time the [ToAssignRef] was completed
[Reason] - A code to indicate why an item could not be picked - AKA F3'd

An operative would be allocated a movement, connected to the [ToAssign Ref], containing a number of products to pick. If an item can not be picked for some reason the operative presses F3 and selects a reason (no stock, damaged etc). These F3'd items (other stock allowing) will later be picked on a different [Movement]. I need a query to identify the subsequent [Movements] and the associated fields following the occurance of an F3'd [ToAssignRef] & [Product].

I have a query, but it runs very slowly (perhaps due to the DB size currently 780K records). Is this the right approach, is there a better (faster) way to do this?

Code:
SELECT PickData.ToAssignRef, PickData.Product, PickData.Picked
FROM PickData
GROUP BY PickData.ToAssignRef, PickData.Product, PickData.Picked
HAVING (((DCount("[Movement]","[PickData]","([ToAssignRef]='" & [ToAssignRef] & "') AND ([Product]='" & [Product] & "')"))<>0));

View 2 Replies View Related

Reports :: Showing All Detail Records If One Record In Query Meets Criteria

Mar 5, 2013

I am trying to create a report which basically includes the following:

Company, Wages, Contribution.

Each company reports wages for each employee every month. Then they also contribute to a general fund based on a percentage of the wages. For instance:

Company---Employee---Wages---Contribution
CompanyA---EmployeeA---$4000---$40
CompanyA---EmployeeB---$3800---$38
CompanyA---EmployeeC---$3800---$38
CompanyB---EmployeeA---$4200---$42
CompanyB---EmployeeB---$4200---$42

...and so on.

Each employee is required to contribute, in this example, 1% of gross wages to the general fund.

On occasion, the company does not pay in the required 1% of gross, say, for CompanyA EmployeeA, they only paid in $35.

Here is what I need to do. If any contribution amount for any employee is incorrect, I want to display all the records for that company, not just the incorrect ones. The report is grouped by Company, and may contain dozens of companies.

I am already passing a number of criteria to the report using a filter, including the date range and other fields which are informational.

View 6 Replies View Related

Queries :: Insert Text From Textbox On A Form When Combo Box Meets Criteria?

Jul 12, 2013

Is it possible to insert text from a textbox on a form (Data) when a combobox on (Data) meets a criteria?

Example: Test: IIf([Results]="Positive" text207)

So if the Results combobox is Positive then the text from Text207 is inserted.

View 9 Replies View Related

General :: Importing Excel Data To Listbox In Access VBA Code

Aug 9, 2013

Need importing just 1 column from excel file into vba !

View 1 Replies View Related

Modules & VBA :: Writing Code To Open Query After User Selected Fields To Include From ListBox

Jan 14, 2014

Access 2007-10
Listbox created: List62 (I know I need to rename it, but for now)
Multi-select: Extended
Row Source Type: Field List
Row Source: qryFieldList
Open Query: qrySelectedFields (I added primary key to first column, just to have at least one destination field).

Goal: to select multiple fields within listbox, click on command button to open query "qrySelectedFields" with selected fields from list box.This is the code I have on the command_click:

Dim varItem As Variant
Dim strSQL As String
If Me.List62.ItemsSelected.Count = 0 Then
MsgBox "Please select one or more fields.", vbExclamation, "Healthcare REIT"
Me.List62.SetFocus
End If

[code]....

It does absolutely nothing - doesn't add the fields to "qrySelectedFields", doesn't open the query, notta.

View 8 Replies View Related

Modules & VBA :: Criteria On MS Access Query Not Working With Multi-Select Listbox

Aug 22, 2014

I am attempting to filter records using a multi-select listbox, but all records are being returned. Here is my code.

Private Sub btnKeyboxCount_Click()
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String

[Code] ....

View 1 Replies View Related

Modules & VBA :: Checking Multiple Criteria Search Code Is Correct?

Feb 25, 2015

Staff are monitored to make sure they are keeping up to date with our customers. A customer can have multiple projects going through the factory at any one time. Each customer has a record per project and a 'general' record. Ideally we would like our staff to be able to move the 'general' record when they update a project record as opposed to either having to find and then update the general record after, or forgetting and calling the customer again 2 days later!

Including a msgbox for the EnqNum seems to show the general record correctly, however being new to access I am unsure if I have the update part correct.

Code:
If Me.chkMoveGen.Value = "-1" Then
Dim EnqNum As Integer
EnqNum = DLookup("[e_id]", "tblEnquiries", "[c_id]=" & Me.txtc_id & " and [e_status] = " & "13")
DoCmd.RunSQL "UPDATE tblEnquiries " & _
" SET e_date_due=#" & Format(Me.txte_date_due, "MM/DD/YYYY") & "#" & _
" WHERE e_id= EnqNum"

View 3 Replies View Related

Modules & VBA :: Export Data In Listbox To Excel

Jun 18, 2014

I have a Listbox named List5 and a search textbox named txtProperty and a table name sms , after i search in textbox the results in listbox . i would link to inport the results in listbox to excel but the code i have export the whole table to excel .

here is my code

''''''''*''''''''*''''''''*''''''''*''''''''*''''' '''*''''''''*''''''''*'
''''''''*''''''''*'''''''' BUTTON 3 ''''''''*''''''''*''''''''*'''''''
''' EXPORT THE LIST TO EXCEL AS List5.XLS ''''''''*''''''''*''
''''''''*''''''''*''''''''*''''''''*''''''''*''''' '''*''''''''*''''''''*'
''''''''*''''''''*''''''''*''''''''*''''''''*''''' '''*''''''''*''''''''*'

Dim outputFileName As String
Dim oXL As Object
Dim oExcel As Object
Dim sFullPath As String
Dim sPath As String
outputFileName = CurrentProject.Path & "List5.xls"

[Code] ....

View 3 Replies View Related

Modules & VBA :: Adding Data In Listbox From Access Table

Jun 5, 2014

The following code gives me runtime error message "couldn't set the list property , Type mismatch".

Private Sub UserForm_Initialize()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim ws1 As Worksheet
Dim j As Long
j = 0

[Code] ....

View 3 Replies View Related

Modules & VBA :: Continuous Form With Data From Table - Populating Listbox From Recordset

Nov 28, 2013

I'm trying to populate a listbox from a recordset. I will explain what I'm trying to achieve.

I have a (continuous) form with some data from a table. On the form header I have a listbox, showing all (distinct) customers from that form.

The user is able to do some filtering. That all works great. But I want to populate the listbox with ONLY the customers on the form AFTER filtering.

One way I thought might me the solution was using RecordClone. But I'm stuck there. It must be something simple for an expert. I'm not entirely a newbie, at least not to VBA. Is there an easy way to refer the listbox' recordset to the actual recordset on the form?

View 1 Replies View Related

Modules & VBA :: Reading Web Page Source Code Data?

Feb 13, 2014

Any method of reading web page source code data.

I am trying to create an event similar to a web query in Excel.

The table in question is not a html table but an asp.net table I think.

View 3 Replies View Related

Modules & VBA :: Code To Copy Partial Data To Another Form / Table

Jul 16, 2014

I have prepared a table in a database which includes a yes no box to one of the fields.

The idea of the yes/no field is that this is recording if the record is awarded. What i would like to achieve is that if the yes no box is checked "True" i would like to be able to copy some of the data from this table into a new table and that the form associated with this table opens up to enable the user to populate the remaining fields.

I believe i need to run this as an on click event procedure but cannot identify the code to enable the data to be copied accross to the other table.

View 14 Replies View Related

Modules & VBA :: Code To Delete Table And Then Run 4 Append Queries To Refresh Data

Jun 11, 2014

I have a table called "EquipmentRequired" which is populated by 4 append queries,

5000BaseReq, 6000BaseReq, 6000IFBBReq, EquipmentReq which get some of their information by counting fields in another table but all have the same field names.

The queries contain all data that is initially used to append new records to the table and this works fine.Unless some information changes or a record is added then I would like to add a button to a form and call it "update equipment" behind which would run a vba code firstly to delete all the records in "EquipmentRequired" table then run the 4 queries without the warnings and re-populate the table.

View 9 Replies View Related

Copying Data Within Same Form From A Listbox Containing A Query To A Blank Listbox?

Apr 21, 2006

Hi, I'm new here, so I hope I'm posting this in the correct place. I've searched the forum to see if there are any existing threads that might help me, but I've not found anything that does...
(I think this thread ( http://www.access-programmers.co.uk/forums/showthread.php?t=93444&highlight=Copying+data )may be trying to achieve something similar to me, but I'm a beginner and don't really understand it)

I shall stop waffling! I'm not entirely sure that what I'm trying to achieve is possible, I expect it probably is!

Right, I have a form (frmGroupRegister, which contains exactly the same fields as the table it comes from, tblGroupRegister), which consists of three things:

-GroupDate - The date a group took place on. It is my primary key, as no more than one group occurs on a specific date.

-ParentList (A listbox which contains a query showing the ID number, forename and surname of everyone in a table, tblParentDetails)

-ParentsAttending (A blank listbox)

I would like to place buttons in between the ParentList and ParentsAttending, which would allow users to conduct a 'register' of attendance by copying individual/multiple details from ParentList into ParentsAttending (much like you get when choosing which fields to include in a form when using a wizard for example). I would also like them to be able to remove people from ParentsAttending by using a button in case of accidentally adding the wrong person into the ParentsAttending box.

I'm aware that another, probably simpler way of achieving this would be to use a tick-box system, but I feel that visually, the first method would both look better and demonstrate who is present more clearly.

Any help would be much appreciated, but my Access skills are quite basic and things will probably need to be spelled out for me.
I'm using Access 2000 and Windows XP.
Thanks for your help,
Alice :)

View 1 Replies View Related

Listbox Code

Jan 24, 2005

I have a form "frmMAINEntry" with a tabcontrol with several pages. The form's Record Source is a query "qryMainData"; however, on two of the pages there's a difference. On the page "Program List" I have a listbox that has a Row Source to table "tsubProgramList" and on the page "Program Details" I have a subform that's Record Source is also "tsubProgramList". The two pages of the tabcontrol are: "ctlProgramDetails" and "ctlProgramList".

The table tsubProgramList contains these fields:
ProgramID..............AutoNumber
Program Description...Text
Facility...................Text
ProgramCoordinator...Text

I'm trying to develop code that will allow me to doubleclick on an item in the listbox which will change tab pages and display the selected record in the subform that's on the other tab page. See code below:

Code:
=================================================
Private Sub lstPrograms_DblClick(Cancel As Integer)
Dim rs As Object
Dim db As Database
Set db = CurrentDb()
Set rs = Forms![frmMainEntry]![fctlProgramList].Form.Recordset.Clone
rs.FindFirst "[ProgramID]" = " & Str(Nz(Me![lstPrograms], 0))"
If Not rs.EOF Then Forms![frmMainEntry]![fctlProgramList].Form.Bookmark = rs.Bookmark
Me![ctlProgramDetails].SetFocus
Call HideNavButtons
End Sub
=================================================
Someone's help would be greatly appreciated.

PC

View 3 Replies View Related

ListBox Code

Jul 19, 2005

I used one of the listbox search functions from the forums and changed it a bit to suit my needs.

I'm not having any errors in the code but I'm not getting any results in my listbox after I search. Also, when I type in what I'm searching for the letters always start in the left so i ended up spelling my words backwards.

This is what I have:


Private blnSpaceBar As Boolean
Option Compare Database
Option Explicit
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 32 Then blnSpaceBar = True

End Sub

Private Sub Form_Load()
On Error Resume Next
SetListDefaultRowSource

Me.txtFilter.Enabled = True
Me.txtFilter = ""
DoCmd.GoToControl "txtFilter"
End Sub


Private Sub ComboParent_AfterUpdate()
Me.ComboChild.Requery
End Sub

Private Sub ComboChild_AfterUpdate()
Me.LstFindings.Requery
End Sub

Private Sub txtFilter_Change()
If IsNull(Me.txtFilter) Then
SetListDefaultRowSource
Exit Sub
Else
If blnSpaceBar = True Then
Me.txtFilter = Me.txtFilter & " "
blnSpaceBar = False
End If
Me.txtFilter.SelStart = Len(Me.txtFilter)
End If
End Sub


Sub SetListDefaultRowSource()
LstFindings.RowSource = _
"SELECT DescriptionID, ElevationID, TradeID, RoomID, Description, Cost, Retail, Markup" & _
"FROM NEWDESCRIPTIONS" & _
"WHERE NEWDESCRIPTIONS.ModelID = [Forms]![frmExample]![ComboChild]" & _
"ORDER BY NEWDESCRIPTIONS.Description"

End Sub



Does anyone have an idea of what I need to do?

thanks very much,
joëlle

View 14 Replies View Related

What Wrong With This Listbox Code?

Dec 14, 2005

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Logins"
stLinkCriteria = "[ID]=" & "'" & Me![lstLogins] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

This code is on the doubleclick event.

lstLogins is sourced from this: SELECT Logins.[ID], Logins.[Login for] FROM Logins WHERE (((Logins.Customer)=[forms]![customers]![customer]));

When i run it I get a VB error "The OpenForm action was cancelled", and the debugger stops on the last line above (Do.Cmd...)

Any ideas why?

I know [ID] is a long integer, but I tried formatting it with Str just in case and it made no difference :(

View 2 Replies View Related

Modules & VBA :: Data Type Mismatch In Criteria Expression

Nov 8, 2014

The error I'm getting is "data type mismatch in criteria expression".

Private Sub BtnAddBooking_Click()
Dim CustomerID As String
Dim StaffID As String
Dim intPos As Integer
Dim strSQL As String
Dim strSQL2 As String
Dim BathValue As Integer
Dim rst As DAO.Recordset
Dim RemainingBookingExists As String
Dim RemainingBaths As Integer
Dim RemainingBathsExists As String

[code]....

View 2 Replies View Related

Modules & VBA :: Query Data Using Multiple Criteria From A Form

May 29, 2014

I have a form where varying layers of information can be entered. In some cases, a user may know all information or only part. If i tie the query to the form, each field has to be populated for it to work. how do i set the query up to effectively use the information available and not require all information?

I have tried setting VBA code as follows:

If Me.Combo1 = Null Then Me.Combo1 = "*"

However, when i do this, it updates the form field with an asterick/wild card but does not include in query. yet, when i update the form fields with data (not asterisk/wild card) the query runs.

View 13 Replies View Related

Problem With Code In Multiselect Listbox

Jan 27, 2005

Hi,

I have adapted code from ghudson's example on
'http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=52736

I have a subform called frmsJobPartsUsed, which contains a multiselect list box where the user can select multiply parts used for one job and click a save button, which saves the parts to rows on the same forms (see picture). The user then enters the number used and that number is taken away from the UnitsInStock.
This form is made up of the following two tables;
TblStore
PartNo
PartName
UnitsInStock
ReOrderLevel
Discountinued
Remark

tblPartsUsed
PartUsedID
JobDetailsID
PartNo
PartUsedNum
NumberUsed

The multiselect listbox is made form tblStore, PartNo, PartName and Discontinued = 0

This all works fine so far.

What is need to do is before the parts selected are saved to the table I want to run some code to check
If a part’s UnitsInStock is equal to 0 then Message box saying no stock left need to reorder. It won’t save it to the table.
Or else
If UnitsInStock is greater than 0 but less than or equal to ReOrderLevel
Message box saying Stock running low need to reorder asap.

I have this kind of working but it doesn’t seem to be finding the correct UnitsInStock for the part selected.
Here is the code;


Private Sub cmdAnswer_Click() 'SAVE BUTTON
On Error GoTo ErrMsg:

'Code adapted from ghudson's example on
'http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=52736

Dim myFrm As Form, myCtl As Control
Dim mySelection As Variant
Dim iSelected, iCount As Long

Dim myDB As DAO.Database
Dim myRst As DAO.Recordset
Dim myRstCount As DAO.Recordset

Set myDB = CurrentDb()
Set myRst = myDB.OpenRecordset("tblPartsUsed")

Set myFrm = Me
Set myCtl = Me.lstAnswers

iCount = 0
'Count number of selected records/items
For Each mySelection In myCtl.ItemsSelected
iCount = iCount + 1
Next mySelection

'Check if anything is slected
If iCount = 0 Then
MsgBox "There are no Parts selected..", _
vbInformation, "Nothing selected!"

Exit Sub
End If

StrSQLCount = "SELECT tblPartsUsed.JobDetailsID, Count(tblPartsUsed.PartNo) AS CountOfPartNo " & _
"FROM tblPartsUsed " & _
"GROUP BY tblPartsUsed.JobDetailsID " & _
"HAVING (((tblPartsUsed.JobDetailsID)=" & [Forms]![frmJobs]![JobDetailsID] & "));"
Set myRstCount = myDB.OpenRecordset(StrSQLCount, dbOpenSnapshot)




'SART OF MY CODE TO CHECK FOR UNITSINSTOCK

For Each mySelection In myCtl.ItemsSelected
If Me.UnitsInStock.Value = 0 Then
MsgBox "Out of Stock!" & Chr(13) & "Please returen to Orders or Store to Re-Order Stock. " & Chr(13) & " ", vbOKOnly + vbCritical, "Re-Order Stock"
myCtl.Selected(mySelection) = False

Else
If Me.UnitsInStock.Value > 0 And Me.UnitsInStock <= Me.ReOrderLevel.Value Then
MsgBox "The Store is running low on stock!!" & Chr(13) & " Please return to Orders or Store to re-order as soon as possible.", vbInformation, "Need to Re-Order Stock"
End If
End If
Next mySelection
'END





iCount = 0

'Go throught each selected 'record' (ItemsSelected) in listbox
For Each mySelection In myCtl.ItemsSelected
'Current count of selected items
iCount = iCount + 1
'Print value to Immediate Window
Debug.Print myCtl.ItemData(mySelection)
'Add answers
With myRst
.AddNew
.Fields("JobDetailsID") = Forms![frmJobs]![JobDetailsID]
.Fields("PartUsedNum") = iCount
.Fields("PartNo") = myCtl.ItemData(mySelection)
.Update
End With
Next mySelection

'Requery form
Me.Requery

ResumeHere:
Exit Sub

ErrMsg:
MsgBox "Error Number: " & Err.Number & _
"Error Description: " & Err.Description & _
"Error Source: " & Err.Source, vbCritical, "Error!"
Resume ResumeHere:

End Sub



Private Sub cmdUnselect_Click() 'UNSELECT BUTTON
On Error GoTo ErrMsg:

'Code adapted from ghudson's example on
'http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=52736

Dim myFrm As Form, myCtl As Control
Dim mySelection As Variant
Dim iSelected, iCount As Long

Set myFrm = Me
Set myCtl = Me.lstAnswers

'Count number of selected records/items
For Each mySelection In myCtl.ItemsSelected
iCount = iCount + 1
Next mySelection

If iCount = 0 Then
MsgBox "There are no selections to Un-Select..", _
vbInformation, "Nothing selected!"
End If

'Go throught each selected 'record' (ItemsSelected) in listbox
For Each mySelection In myCtl.ItemsSelected
Debug.Print myCtl.ItemData(mySelection)
myCtl.Selected(mySelection) = False
Next mySelection

ResumeHere:
Exit Sub

ErrMsg:
MsgBox "Error Number: " & Err.Number & _
"Error Description: " & Err.Description & _
"Error Source: " & Err.Source, vbCritical, "Error!"
Resume ResumeHere:
End Sub







Any help would be greatly appreciated.
Thanks in advance
Rita

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved