473,385 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Textbox and Subform

Hey guys Probably an easy question but I can't get it to click:

I have a form (frmSearch) that has a subform (frmDatabase) the frmSearch has textboxes that limit the frmDatabase off of that material.

Question: once I get this searched criteria down to 1 entry I want to set the value of the column to a textbox.

EX. (variable) = ColumnA

So if it is only 1 item then the (variable) should equal the text in ColumnA.

Also I have a If statement running to make sure it equals 1

If txtcount.value = 1 then
Global Variable = ColumnA
end if

how can i do that?
Jan 18 '08 #1
1 1631
PianoMan64
374 Expert 256MB
I guess I need to understand the reason why you would want to do that, are you trying to pull a peace of data from a particular column in the table that you displaying in frmDatabase?

If so, I have a few suggestions for you:

1. If you change the frmDatabase to simply be a ListControl in your frmSearch.
2. You then take the input from each of the frields and build your Criteria statement that you're going to pass to the ListControl to display the record(s) on the screen. You can keep displaying it as many times as you want until you get down to a manageable level of data.
3. You then would select from the values that you have displayed in the ListControl to select the particular data item from doubleclicking on the selected item that you want to get the value from.

The following example is taken from an accual project that I worked on before.
Please take note of the variable names and the control names that are used.

the following are Control Name for the List Control
ListInvoices is the name of the List Control
TheAmount is a TextBox Control on the form
TheCompany is the TextBox Control on the form
and so on....

By simply building the string, you can then pass that string to the Listcontrol and requery the listcontrol and it will display that you passed the listcontrol rowsource value.
See code below.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub ClearSearch_Click()
  4.     Me.ListInvoices.RowSource = ""
  5.     Me.TheAmount = Null
  6.     Me.TheCompany = Null
  7.     Me.TheIDNo = Null
  8.     Me.TheInvoiceNo = Null
  9.     Me.TheVendorNo = Null
  10.     Me.TheBatchNumber = Null
  11.     DoCmd.GoToControl "TheIDNo"
  12.  
  13. End Sub
  14.  
  15. Private Sub SearchBtn_Click()
  16.  
  17.     Dim SQL1 As String
  18.     Dim Criteria As String
  19.  
  20.     Me.StatusMsg = "Searching..."
  21.     Me.Repaint
  22.     SQL1 = "SELECT [CFS Invoice View].IDNO as [ID No], [CFS Invoice View].Vendor, " & _
  23.            "[CFS Invoice View].COMPANY, [CFS Invoice View].INVOICENO, " & _
  24.            "[CFS Invoice View].AMOUNT, [CFS Invoice View].RECEIVED, " & _
  25.            "[CFS Invoice View].BatchNo,  [CFS Invoice View].UserName, " & _
  26.            "[CFS Invoice View].Status " & _
  27.            "FROM [CFS Invoice View] " & _
  28.            "WHERE ("
  29.     If IsNull(Me.TheIDNo) And IsNull(Me.TheVendorNo) And IsNull(Me.TheCompany) And IsNull(Me.TheInvoiceNo) _
  30.        And IsNull(Me.TheAmount) And IsNull(Me.TheBatchNumber) Then
  31.        SQL1 = Left(SQL1, Len(SQL1) - 7)
  32.        SQL1 = SQL1 & "ORDER BY [CFS Invoice View].Status DESC;"
  33.     Else
  34.     If Not IsNull(Me.TheIDNo) Then
  35.         If Len(Criteria) > 0 Then
  36.             Criteria = Criteria & " AND (([CFS Invoice View].IDNo)=" & Me.TheIDNo & ")"
  37.         Else
  38.             Criteria = Criteria & "(([CFS Invoice View].IDNo)=" & Me.TheIDNo & ") "
  39.         End If
  40.     End If
  41.     If Not IsNull(Me.TheVendorNo) Then
  42.         If Len(Criteria) > 0 Then
  43.             Criteria = Criteria & " AND (([CFS Invoice View].Vendor)=" & Me.TheVendorNo & ")"
  44.         Else
  45.             Criteria = Criteria & "(([CFS Invoice View].Vendor)=" & Me.TheVendorNo & ") "
  46.         End If
  47.     End If
  48.     If Not IsNull(Me.TheCompany) Then
  49.         If Len(Criteria) > 0 Then
  50.             Criteria = Criteria & " AND (([CFS Invoice View].Company)=" & Me.TheCompany & ")"
  51.         Else
  52.             Criteria = Criteria & "(([CFS Invoice View].Company)=" & Me.TheCompany & ") "
  53.         End If
  54.     End If
  55.     If Not IsNull(Me.TheInvoiceNo) Then
  56.         If Len(Criteria) > 0 Then
  57.             Criteria = Criteria & " AND (([CFS Invoice View].INVOICENO) = '" & Me.TheInvoiceNo & "')"
  58.         Else
  59.             Criteria = Criteria & "(([CFS Invoice View].INVOICENO) = '" & Me.TheInvoiceNo & "') "
  60.         End If
  61.     End If
  62.     If Not IsNull(Me.TheAmount) Then
  63.         If Len(Criteria) > 0 Then
  64.             Criteria = Criteria & " AND (([CFS Invoice View].AMOUNT)=" & Me.TheAmount & ")"
  65.         Else
  66.             Criteria = Criteria & "(([CFS Invoice View].AMOUNT)=" & Me.TheAmount & ") "
  67.         End If
  68.     End If
  69.     If Not IsNull(Me.TheBatchNumber) Then
  70.         If Len(Criteria) > 0 Then
  71.             Criteria = Criteria & " AND (([CFS Invoice View].BatchNo)=" & Me.TheBatchNumber & ")"
  72.         Else
  73.             Criteria = Criteria & "(([CFS Invoice View].BatchNo)=" & Me.TheBatchNumber & ") "
  74.         End If
  75.     End If
  76.  
  77.  
  78.     SQL1 = SQL1 & Criteria & ") ORDER BY [CFS Invoice View].Status DESC;"
  79.  
  80.     'MsgBox SQL1, vbOKOnly
  81.     End If
  82.     Debug.Print SQL1
  83.  
  84.     Me.ListInvoices.RowSource = SQL1
  85.     Me.ListInvoices.Requery
  86.     Me.StatusMsg = ""
  87.     Me.Repaint
  88.  
  89.  
  90. End Sub
  91.  
In order to pull a particular value from the list of items that you have displayed in the ListControl you would have code something like this:

Expand|Select|Wrap|Line Numbers
  1. Sub ListInvoices_DblClick()
  2.          Dim varItem as Variant
  3.          Dim theValueYouWant as Variant
  4.  
  5.          For Each varItem in ListInvoice.ItemsSelected
  6.                   theValueYouWant = me.ListInvoice.Column(1,varitem)
  7.         Next
  8. End Sub
  9.  
If you want to pass that value to a control on the main form that you're working with, then you can, if you want to be able to select that record and open it up in another form for editing, then you can do that also.

If you need more code examples of how to do that, let me know,

Hope that helps,

Joe P.
Jan 20 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: New2Access | last post by:
I posted this yesterday but perhaps I wasn't clear enough. I have a table called History with 4 fields "Week" "Employee" "Project" and "Hours" Each of those fields (except Hours) are based on...
2
by: Zlatko Matić | last post by:
I have several forms hierarchycaly nested in each other (form/subform/subform/subform....). The final form is "continous form", while parent forms are single forms through which navigation was...
2
by: dskillingstad | last post by:
I'm trying to assign a custom value to a textbox. Here's what I have. I've created a module and "default value" code for a textbox which generates a custom auto-number (yyyy-0000) when a New...
1
by: Stephen D Cook | last post by:
I have a form with a query linked subform. Also on the form is a textbox. I want to pull up an AddItem subform if the data in the textbox does not exsist in the table, and a UpdateItem subform...
3
by: luanhoxung | last post by:
Hi all !! i have met trouble with referring textbox of subform in VBA i know i can do as: forms!mainform.subform.textbox but i want do it in shorter path. any suggestion about using variable ?...
14
by: ZaphodBBB | last post by:
Hi O.S. = Windows XP Pro all Service Packs Access = 2003 I have a form with 2 tabbed pages. On the second page I have a subform which populates in Datasheet view with a list of items. One...
17
by: lokidog | last post by:
I am trying to automatically transfer data from one textbox to another between subforms within a 'main' form. I put this code into the Gotfocus eventprocedure: Private Sub Date_GotFocus() If...
11
by: Beany | last post by:
Hi, Can some please provide me with the code for counting records in a subform and displaying it in a textbox? Does this code go into the control source of the textbox? My subform is called...
13
by: BASSPU03 | last post by:
Hello, folks. This is my first post and I only began to work extensively with Access about 3 weeks ago. I'm running Access 2003 on Windows XP. I'd like a textbox in subform2 to reflect the value...
2
by: NerdyGirL | last post by:
Hello, I've read thru numerous post/archives trying to decipher the cause of my problem to no avail. I'm just basically trying to conduct a search by using a form in order to locate data that may...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.