Select count data in access with textbox input value condition

Ngoclong226

New Member
Joined
Mar 20, 2019
Messages
5
Hi
I have a database access with “LAL data” table and “Job_no” field.
I have create a userform in excel with input textbox “txt_jobno”
How can i count the number of fields in access table with criteria as textbox input value.
My code of selecting the data in acess:
Const strSQL_c as string = “select count([LAL data].Job_no) as CountofJob_no From [LAL data] Where ([LAL data].Job_no = “”me.txt_jobno.value””)”
But it did not work.
Could anyone help?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
See if this works better for you:
Is me.txt_jobno.value a variable's value?
If so, I don't think you want quotes around it, i.e.
Code:
[COLOR=#333333]Const strSQL_c as string = "select count([LAL data].Job_no) as CountofJob_no From [LAL data] Where ([LAL data].Job_no = me.txt_jobno.value)"[/COLOR]
 
Last edited:
Upvote 0
Thanks for you help.
I try your solution but it happen error “ no value given for one or more required parameter”. Here is all the code:
Const strSQL_c As String = "SELECT Count([LAL data].Job_No) AS CountOfJob_No FROM [LAL data] WHERE ([LAL data].Job_No = me.Txt_JobNo.Value)"

Const strConnection_c As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\70F4908\Desktop\Programming document\CODE\Production data input project\Data.accdb;Mode=Read;Persist Security Info=False"

Dim cn As ADODB.Connection

Dim rs As ADODB.Recordset

Dim lngCount As Long

Set cn = New ADODB.Connection

cn.Open strConnection_c

Set rs = New ADODB.Recordset

rs.Open strSQL_c, cn, adOpenForwardOnly ‘(this line happen eror)

If Not rs.EOF Then

lngCount = rs.Fields(0).Value

End If
 
Upvote 0
I try your solution but it happen error “ no value given for one or more required parameter”.
I believe that is telling you that it is not receiving any value from "me.Txt_JobNo.Value".

Where exactly have you placed this VBA code?
How is it being called/run?
Are you sure that you have the variable named correctly?

An easy way to check to see if you can get the value in that manner within that code is to place this line at the top of your code, and see what it returns:
MsgBox
me.Txt_JobNo.Value
 
Last edited:
Upvote 0
Hi
I put the code in a command button in a simple input form (1 textbox, 1 button)
When i input a value in textbox then click button, i will return the how many jobno in the database match with the input data.
If i only put the code msgbox txt_jobno.value it still show the correct value i input to the textbox.
 
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,051
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top