wedd
01-03-2012, 07:47 AM
Hi experts, I am developing a database that when users want to search for dates of a booking scheduled or unscheduled,times of an appointment or records of a customer's history based on a ID number of a customer; they just need to enter the number in a text box and click on a button that searches through all the records in the forms and tables...all the possible outcomes based on the date entered or customer name or customerID number entered. Can this be done? If so what will I need to do? Would you know of any logical code that can perform this challenging task? If you have or know of any code through websites or possible programs you've created to do this would be very helpful...I am an intermediate user of vba so it seems a bit complex for me...I created a program to search for records on a form( including new records)based on customer ID numbers...but it only displays a messagebox of the customerID number rather than searching for the actual record and displaying it. (I've listed this code below - maybe you can adjust, adapt or taylor the code to meet my requirements). If you know of a website that has similar samples on how to do this that would also be very useful...
I am creating it in this method rather than using the drop down list because it will be more user friendly for staff at my workplace to use...as they receive a lot of data and need a way to keep track of bookings that have been done...for future dates and years...as well as forthcoming dates...so this way will make it more efficient and quicker to search for a customers record rather than navigating down a long drop down list...
Thanks for your contributions:friends: ...this will definitely enhance my learning of vba for access.
The code I've used to do this: but it only displays a messagebox of the customer's ID number; rather than searching and displaying a historical record, dates of a particular booking; dates when a booking is available or not based on when the user enters a date in the text box...
Private Sub btnSearch_Click()
On Error GoTo Err_btnSearch_Click
If IsNull(Me.TxtSearchValue) Or Len(Me.TxtSearchValue) = 0 Then
MsgBox "You must enter a CustomerID number to Search for in the Blank Box to the right"
Me.TxtSearchValue.SetFocus
Exit Sub
End If
If Left(Me.TxtSearchValue, 1) Like "[0-9]" Then
'searching for number
MsgBox "Use code to search for Number " & vbCrLf _
& "select * from tblCustomers where [Customer ID] =" & CLng(Me.TxtSearchValue)
Else
'searching for Name
MsgBox "Use code to search for Customer Name " & vbCrLf _
& "select * from tblCustomers where [Customer Name] = '" & Me.TxtSearchValue & "'"
End If
Exit_btnSearch_Click:
Exit Sub
Err_btnSearch_Click:
MsgBox Err.Description
Resume Exit_btnSearch_Click
End Sub
I am creating it in this method rather than using the drop down list because it will be more user friendly for staff at my workplace to use...as they receive a lot of data and need a way to keep track of bookings that have been done...for future dates and years...as well as forthcoming dates...so this way will make it more efficient and quicker to search for a customers record rather than navigating down a long drop down list...
Thanks for your contributions:friends: ...this will definitely enhance my learning of vba for access.
The code I've used to do this: but it only displays a messagebox of the customer's ID number; rather than searching and displaying a historical record, dates of a particular booking; dates when a booking is available or not based on when the user enters a date in the text box...
Private Sub btnSearch_Click()
On Error GoTo Err_btnSearch_Click
If IsNull(Me.TxtSearchValue) Or Len(Me.TxtSearchValue) = 0 Then
MsgBox "You must enter a CustomerID number to Search for in the Blank Box to the right"
Me.TxtSearchValue.SetFocus
Exit Sub
End If
If Left(Me.TxtSearchValue, 1) Like "[0-9]" Then
'searching for number
MsgBox "Use code to search for Number " & vbCrLf _
& "select * from tblCustomers where [Customer ID] =" & CLng(Me.TxtSearchValue)
Else
'searching for Name
MsgBox "Use code to search for Customer Name " & vbCrLf _
& "select * from tblCustomers where [Customer Name] = '" & Me.TxtSearchValue & "'"
End If
Exit_btnSearch_Click:
Exit Sub
Err_btnSearch_Click:
MsgBox Err.Description
Resume Exit_btnSearch_Click
End Sub