User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 456,463 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,746 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 1244 | Replies: 10
Reply
Join Date: Sep 2007
Posts: 2
Reputation: Murali1311 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Murali1311 Murali1311 is offline Offline
Newbie Poster

Searching access using VB

  #1  
Sep 16th, 2007
Hi, i am doing a payroll calculation using vb and access. In this, if a user clicks the search button, it should ask the emp_no and if it is present, it should display it. for this i need the codings. I tried some codings, but it doesn't works properly

Additional Information
I connected ms access with vb using addins manager.So give the code related to this. thanks in advance
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2007
Location: Bangalore,India
Posts: 1,444
Reputation: debasisdas is on a distinguished road 
Rep Power: 4
Solved Threads: 87
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Nearly a Posting Virtuoso

Re: Searching access using VB

  #2  
Sep 16th, 2007
Try to implement the search logic using SQL .
Share your Knowledge.
Reply With Quote  
Join Date: Sep 2007
Posts: 7
Reputation: dandonia is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dandonia dandonia is offline Offline
Newbie Poster

Re: Searching access using VB

  #3  
Sep 17th, 2007
hi can i ask why you are add ins manager to connect the database?

its simple stuff using other methods so is there a specific reason you are using yours.
Reply With Quote  
Join Date: May 2007
Location: India
Posts: 501
Reputation: choudhuryshouvi is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 48
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Solution Re: Searching access using VB

  #4  
Sep 18th, 2007
Hope this code can cover up your requirement.

Before try to run this code create a database "employee.mdb" and a table "info" with four fields "emp_no","name","basic","tax". Add some records to test the code. Take a button(cmdsearch) and five textboxes(text1 to text5) and associated five labels. Below is a sample interface that i've used. See it for your consideration.

Regards,
Shouvik

Option Explicit

Private Sub cmdsearch_Click()
Dim db As Database
Dim rs As Recordset
Dim str As String
Dim confirm As Integer

begin:
str = InputBox("Enter Employee No. :", "Search")
If str <> "" Then
Set db = OpenDatabase(App.Path & "\employee.mdb")
Set rs = db.OpenRecordset("select * from info where emp_no='" & str & "'")
If rs.RecordCount > 0 Then
Text1.Text = rs!emp_no
Text2.Text = rs!Name
Text3.Text = rs!basic
Text4.Text = rs!tax
Text5.Text = rs!basic - rs!tax
Else
confirm = MsgBox("Sorry, Employee No. " & Chr(34) & str & Chr(34) & " was not found." & vbCrLf & "Try again?", vbYesNo + vbQuestion, "Search")
If confirm = vbNo Then
Exit Sub
Else
GoTo begin
End If
End If
Set rs = Nothing
Else
confirm = MsgBox("Invalid employee no." & vbCrLf & "Try once again?", vbYesNo + vbQuestion, "Search")
If confirm = vbNo Then
Exit Sub
Else
GoTo begin
End If
End If
End Sub
Last edited by choudhuryshouvi : Sep 18th, 2007 at 1:37 am.
Attached Images
File Type: jpg screen.JPG (14.9 KB, 5 views)
Reply With Quote  
Join Date: Jul 2007
Location: Philippines
Posts: 253
Reputation: jireh is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 28
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz in Training

Re: Searching access using VB

  #5  
Sep 18th, 2007
Hi dandonia!
You can use Addins if you dont have MS Access installed
Reply With Quote  
Join Date: Jul 2007
Location: Philippines
Posts: 253
Reputation: jireh is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 28
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz in Training

Re: Searching access using VB

  #6  
Sep 18th, 2007
Hi Murali1311!
try this one too.
Dim dbase As Database
Dim tmpRs as Recordset

Set dbase=OpenDatabase(App.Path & "\Sample.mdb")
Set tmpRs=dbase.OpenRecordset("SELECT * from [table info] where EmployeeNumber='" & Searchtxt.Text & "'")
  If Not tmpRs.BOF Then
       With tmpRs
           text1.Text = !employeename
           text2.text = !Address
           ...and so on
       End With
   Else
      MsgBox "Employee Number not found.", VBInformation
   End If
Reply With Quote  
Join Date: Sep 2007
Posts: 7
Reputation: dandonia is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dandonia dandonia is offline Offline
Newbie Poster

Solution Re: Searching access using VB

  #7  
Sep 19th, 2007
Originally Posted by jireh View Post
Hi dandonia!
You can use Addins if you dont have MS Access installed


K, thanks. I didn't know he didnt have Access installed.
Reply With Quote  
Join Date: Sep 2007
Posts: 2
Reputation: Murali1311 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Murali1311 Murali1311 is offline Offline
Newbie Poster

Help Re: Searching access using VB

  #8  
Sep 19th, 2007
Originally Posted by dandonia View Post
hi can i ask why you are add ins manager to connect the database?
Hi, Thanks for your reply

its simple stuff using other methods so is there a specific reason you are using yours.

Hi, Thanks for your reply

Actually, I feel that connecting Access with VB using a Visual manager will be simple and easy. So that no extra coding will be needed. Extra coding in the sense
dim rs as recordset e.t.c

So, i don't want to connect the database(MS Access) using the codings. I connected the database already. My problem is the search option is not working properly. Now i cured the problem. BUt still i can't search a item, If it contains alphanumeric characters. Say, asp345.

Give a coding for this. Thanks in advance
Reply With Quote  
Join Date: May 2007
Location: India
Posts: 501
Reputation: choudhuryshouvi is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 48
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Searching access using VB

  #9  
Sep 20th, 2007
use the "Like" operator

Sample sql :-

"select * from employee where emp_name like '*S*'"
Reply With Quote  
Join Date: Feb 2007
Location: Bangalore,India
Posts: 1,444
Reputation: debasisdas is on a distinguished road 
Rep Power: 4
Solved Threads: 87
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Nearly a Posting Virtuoso

Re: Searching access using VB

  #10  
Sep 20th, 2007
As already suggested ,try to implement the search logic using SQL . Try to use Pattern matching using LIKE search.
Share your Knowledge.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 2:19 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC