•
•
•
•
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
![]() |
•
•
Join Date: Sep 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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
Additional Information
I connected ms access with vb using addins manager.So give the code related to this. thanks in advance
•
•
Join Date: Feb 2007
Location: Bangalore,India
Posts: 1,444
Reputation:
Rep Power: 4
Solved Threads: 87
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
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.
•
•
Join Date: Jul 2007
Location: Philippines
Posts: 253
Reputation:
Rep Power: 0
Solved Threads: 28
Hi dandonia!
You can use Addins if you dont have MS Access installed
You can use Addins if you dont have MS Access installed
•
•
Join Date: Jul 2007
Location: Philippines
Posts: 253
Reputation:
Rep Power: 0
Solved Threads: 28
Hi Murali1311!
try this one too.
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•
•
Join Date: Sep 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb Visual Basic 4 / 5 / 6 Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Searching for a record in multiple tables (VB.NET)
- Access to the path is denied (ASP.NET)
- Searching for a string in an access database (Visual Basic 4 / 5 / 6)
- Can't access secure websites - have tried everything (Windows NT / 2000 / XP / 2003)
- IE; Getting file download box when attempting to access a particular web page (Web Browsers)
- Unable to access web site (Web Browsers)
- Searching for records contained in access from VB (Visual Basic 4 / 5 / 6)
- try to access Active Directory in .NET -->system.runtime.interopservices.comexception (VB.NET)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Word Count in Crystal Report
- Next Thread: SS tabs



Linear Mode