Hello,
Almost a newbie at VB and First time question in this forum!
I have a form "MAIN" with: - 2 unbound textboxes ("startdate" and "endate") - 1 optiongroup with 2 options (value "1" & "2") - 1 unbound multiselect listbox "accountlist" shown if optiongroup value is "1" taking its (grouped) values from transactions table. and a Subform "SUBFORM" with:- account, transactiondate, amount fields taken from transactions table I would like to get the result of a query in subform with the following variables:- "transactiondate">="startdate" AND <="Endate" values taken from textboxes - if optiongroup = 1, limit the result to those accounts selected in "accountlist" multiselect listbox - if optiongroup = 2, select all accounts Thank you very much for your precious help!
9 1536 NeoPa 32,556
Expert Mod 16PB
What SQL do you use to get all the info you want?
What are the names of the individual Options in the Option Group?
What SQL do you use to get all the info you want?
What are the names of the individual Options in the Option Group?
I don't get your first question, do you mean how do i get the info on the main form?
If your question is related to the SQL needed to update the subform, it is definitely part of my request!
The individual options names in the option group are:
-option1account
-option2allaccounts
thanks a lot !
NeoPa 32,556
Expert Mod 16PB
Thank you for the option names.
My first question meant :
What is the Record Source of the forms?
For subforms - what are the linked fields?
Please provide MetaData for any tables.
Here is an example of how to post table MetaData : Posting Table/Dataset MetaData - Table Name=tblStudent
-
StudentID; Autonumber; PK
-
Family; String; FK
-
Name; String
-
University; String; FK
-
MaxMark; Numeric
-
MinMark; Numeric
Thank you for the option names.
My first question meant :
What is the Record Source of the forms?
For subforms - what are the linked fields?
Please provide MetaData for any tables.
Ade
I think the main form is unbound and he wants to use the controls to set the record source for the subform.
Mary
Firstly, you will need to add a command button to generate the records in the subform.
Create the subform to show all accounts of all dates i.e. the transactions table. Don't have any relationship i.e. master/child between the subform and the main form.
Then in the code behind the command button you will need the following: -
Private Sub commandXX_Click()
-
Dim strSQL As String
-
Dim itemVal As Variant
-
Dim accList() As Variant
-
Dim count As Integer
-
-
count = 0
-
-
SELECT CASE optGroupName
-
CASE 1
-
For Each itemVal In Me.accountlist.ItemsSelected
-
accList(count) = Me.accountlist.ItemData(itemVal)
-
count = count + 1
-
Next itemVal
-
-
strSQL = "SELECT account, transactiondate, amount fields " & _
-
"FROM transactions WHERE (transactiondate " & _
-
"BETWEEN #" & Me.startdate & "# AND #" & Me.Endate & "#) " & _
-
"AND account IN (" & accList & ");"
-
CASE 2
-
strSQL = "SELECT account, transactiondate, amount fields " & _
-
"FROM transactions WHERE (transactiondate " & _
-
"BETWEEN #" & Me.startdate & "# AND #" & Me.Endate & "#);"
-
END SELECT
-
-
Me.SubformName.RecordSouce = strSQL
-
Me.SubformName.Requery
-
-
End Sub
-
-
Mary
NeoPa 32,556
Expert Mod 16PB
Something like this should at least start you off : - Private Sub txtStartDate_AfterUpdate()
-
Call SetSQL()
-
End Sub
-
-
Private Sub txtEndDate_AfterUpdate()
-
Call SetSQL()
-
End Sub
-
-
'Add similar procedures for listbox & option group
-
-
Private Sub SetSQL()
-
Dim strSQL As String, strWork As String
-
-
strSQL = "SELECT *" & VbCrLf & _
-
"FROM [Transactions]" & VbCrLf & _
-
"WHERE ([TransactionDate] Between " & _
-
Format(Me.StartDate,"\#m/d/yyyy\#") & _
-
" And " & _
-
Format(Me.EndDate,"\#m/d/yyyy\#") & ")"
-
If option1account Then
-
'In here put code to add items to a string (strWork)
-
'formatted as a list separated by commas.
-
'Single-quotes should be used to surround each list item
-
strSQL = strSQL & " AND ([Account] In(" & strWork & "))"
-
End If
-
Forms!MainForm.[YourSubFormControl].RecordSource = strSQL
-
End Sub
Hello guys,
thank you for your posts, were really helpful.
Here is the code I could get to work: - Private Sub SetSQL()
-
Dim strSQL As String
-
Dim strWhere As String
-
Dim itemVal As Variant
-
Dim accList() As Variant
-
Dim count As Integer
-
Dim lngLen As Long
-
Dim messqge As String
-
-
strSQL = ""
-
-
strSQL = "SELECT *" & vbCrLf & _
-
"FROM [Transactions_table]" & vbCrLf & _
-
"WHERE ([Trade date] Between " & _
-
Format(Me.StartDate, "\#mm/dd/yyyy\#") & _
-
" And " & _
-
Format(Me.End_Date, "\#mm/dd/yyyy\#") & ")"
-
-
-
If Forms![Transactions].[Accountselect] = 1 Then
-
-
With Me.accountlist
-
For Each itemVal In Me.accountlist.ItemsSelected
-
If Not IsNull(itemVal) Then
-
strWhere = strWhere & """" & .ItemData(itemVal) & """, "
-
End If
-
Next
-
End With
-
lngLen = Len(strWhere) - 2 'Without trailing comma and space.
-
If lngLen > 0 Then
-
strWhere = "[account] IN (" & Left$(strWhere, lngLen) & ")"
-
strSQL = strSQL & " AND " & strWhere
-
End If
-
-
End If
-
strSQL = (strSQL & vbCrLf & "ORDER BY [Trade date];")
-
-
Me.Transactions_Query_subform.Form.RecordSource = strSQL
-
-
End Sub
That's great.
I'm glad you got it working.
Mary
NeoPa 32,556
Expert Mod 16PB
Yes, I'm pleased for you.
Particularly as you've picked up from the suggestions and taken it further by yourself :).
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John |
last post by:
Hi - I am trying to perform a simple append query, with no luck. I
have a table (MktPrices) that has the following fields: BondID,
PriceDate, Price. The objective is to allow the user to input a...
|
by: cassandra.flowers |
last post by:
Hi,
I was wondering if it is possible (Using access) to have a query parameter
as a drop down box rather than a text box?
e.g. typing as criteria for a query produces a box with a
text box...
|
by: Jason |
last post by:
I have a primary form which is used to enter/edit data in a table
named Test_Results. On this primary form there is a subform which
displays site addresses. This subform is linked to the primary...
|
by: Joe.Mobley |
last post by:
All,
When you sell a product we require access to remove that information
from the stock table, so the product is sold througha comobo box named
"Combo4" under the prodcuts sold form which is a...
|
by: Smartin |
last post by:
Using Access 97
I am trying to create a form that allows for user entry of search terms
and displays a table of results. I thought I could accomplish this using
a subform but it isn't quite...
|
by: Stephen D Cook |
last post by:
I have a form with txtSN text box, btnShow button, and a subform. The
form is bound to a Table. The button is bound to a lookup query. The
query is bound to the text box.
I want to be able to...
|
by: Stephen D Cook |
last post by:
I have a form linked to a table. In the form I have a textbox, a
command button, and a query subform.
I dragged the query onto the form to create the query subform.
The query has a field named...
|
by: Macbane |
last post by:
Hi There,
I have a main form that with a subform which is based on a parameter
query. I have 2 controls on the main form &
which are used as parameters in the query. It all works fine and...
|
by: kabradley |
last post by:
Hello Everyone,
So, thanks to nico's help I was finally able to 'finish' our companies access database. For the past week or so though,I have been designing forms that contain a subform and an...
|
by: jcf378 |
last post by:
Is it possible to set a main-form with an embedded subform to "Filter by Form", subsequently enter the desired variables in fields in BOTH the main-form and subform, and then save the resulting...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |