Solved

Count records using a wildcard...

Posted on 2008-06-18
3
220 Views
Last Modified: 2013-12-25
I am trying to setup a Count routine that will use a wildcard to find all records in a certain field within a certain table that starts with a specified number (comes from a text box) but I don't think the wildcard is working because no matter what I enter it doesn't find a Count (always 0). Any idea what I might be doing wrong now?

thanks in advance for any help that you can give me with this.

Also tried...
cmd.Parameters.AddWithValue("@CurrDepart", OleDbType.VarChar).Value = Me.txtCurGL.Text.ToString & "%"
'Check to make sure the Current Department already exisits
            Dim Count2 As Integer = 0
            Using Connection As New OleDbConnection _
             ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Comet 631 Databases\Converted to 2003\C022008.mdb")
                Dim cmd As OleDbCommand = New OleDbCommand _
                ("Select Count(ActAcct) as ExistingRecords From [SHACT] where (ActAcct)= @CurrDepart", Connection)
                cmd.Parameters.AddWithValue("@CurrDepart", Me.txtCurGL.Text.ToString & "%")
                 Connection.Open()
                Count2 = CInt(cmd.ExecuteScalar)
                ("@CurrDepart",me.txtCurGL.text.Tostring & "%")end withconnection.open()
            End Using
            'if the Current Department doesn't exisit then throw message and exit sub
            If Count2 <= 0 Then
                MessageBox.Show("The GL Department " & Me.txtCurGL.Text.ToString & " does not exisit.", _
                "Copy Department", MessageBoxButtons.OK)
                Me.txtCurGL.Focus()
                Me.txtCurGL.SelectAll()
                Return
            End If

Open in new window

0
Comment
Question by:Boon01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
nexusnation earned 250 total points
ID: 21815531
You can do:

"Select Count(ActAcct) as ExistingRecords From [SHACT] where (ActAcct) Like @CurrDepart"

And the "%" might need to be "*". (Not sure; I don't recall the syntax).

You might also need single quotes. I'd eliminate the parameter and try this directly:

"Select Count(ActAcct) as ExistingRecords From [SHACT] where (ActAcct) Like '" & Me.txtCurGL.Text & "%'", Connection)
0
 
LVL 1

Author Comment

by:Boon01
ID: 21815716
Thank you very much nexusnation, "Select Count(ActAcct) as ExistingRecords From [SHACT] where (ActAcct) Like '" & Me.txtCurGL.Text & "%'", Connection) was the answer. I had tried this but had a typo in it so it gave an error and I tried the Paameter instead. But this worked like a charm, thanks again!!
0
 
LVL 12

Expert Comment

by:nexusnation
ID: 21815779
Glad I could help!
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
T-sql Date Format 9 67
T-SQL: Only Wanting One Record 8 61
T-SQL: Need to trim a single leading space 7 62
Click print button programmatically on print showdialog 1 24
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

751 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