create search form

G

Guest

I have created a table with my booklist with title, author, type, etc. i
want to create a form to search my collection by title, author, kind, etc.
how do i do that? i went to design view and created a combo box for the
sections, and a text box to enter what to search for. i don't know how to do
the search button.

i'm using access 2003 on windows xp
 
G

Guest

hi,
here is code i used that does about what you want to do. the form open from
a main form. it has 4 check boxes each states a different criteria, 1 text
box for date, 2 text boxes for name and id and 2 buttons, one button to close
the form and return to main form and 1 to run 1 of 5 different reports based
on which combo box was checked.
as is , it wont work for you but you can use it as sample code and design
your own code to work for you. this code contains 9 different subs. one for
each check box and one for each button and 1 for form load and 1 for a lookup.

regards
FSt1

Private Sub chkCurrent_Click()

If Me.chkCurrent = True Then
Me.ChkOld = False
Me.ChkNegBal = False
Me.chkDate = False
Me.txtDateInput.Enabled = False
Me.txtDateInput = Null
Me.txtEmpID.Enabled = True
Me.txtEmpName.Enabled = True
Me.txtEmpID = Null
Me.txtEmpName = Null
Me.txtEmpID.SetFocus
End If

End Sub

Private Sub chkExEmp_Click()

If Me.chkExEmp = True Then
Me.ChkOld = False
Me.ChkNegBal = False
Me.chkCurrent = False
End If

End Sub

Private Sub chkDate_Click()

If Me.chkDate = True Then
Me.ChkOld = False
Me.ChkNegBal = False
Me.chkCurrent = False
Me.txtDateInput.Enabled = True
Me.txtEmpID.Enabled = True
Me.txtEmpName.Enabled = True
Me.txtEmpID.Enabled = False
Me.txtEmpName.Enabled = False
Me.txtEmpID = Null
Me.txtEmpName = Null
Me.txtDateInput.SetFocus
End If

End Sub

Private Sub ChkNegBal_Click()

If Me.ChkNegBal = True Then
Me.chkCurrent = False
Me.ChkOld = False
Me.chkDate = False
Me.txtDateInput.Enabled = False
Me.txtDateInput = Null
Me.txtEmpID.Enabled = False
Me.txtEmpName.Enabled = False
Me.txtEmpID = Null
Me.txtEmpName = Null
End If

End Sub

Private Sub ChkOld_Click()

If Me.ChkOld = True Then
Me.chkCurrent = False
Me.ChkNegBal = False
Me.chkDate = False
Me.txtDateInput.Enabled = False
Me.txtDateInput = Null
Me.txtEmpID.Enabled = True
Me.txtEmpName.Enabled = True
Me.txtEmpID.SetFocus
End If

End Sub

Private Sub cmdAccept_Click()

If Me.chkCurrent = False And Me.ChkNegBal = False And Me.chkDate = False
And Me.ChkOld = False Then
MsgBox "Please check one of the Check Boxes at the top.", , "Program
needs directions"
Exit Sub
Else
If Me.ChkNegBal = True Then
DoCmd.OpenReport "rptPTONegBals", acViewPreview
Else

If Me.chkCurrent = True Then

If IsNull(Me!txtEmpID) Then
MsgBox (" Enter an Employee ID.")
Me.txtEmpID.SetFocus
Exit Sub
Else
DoCmd.OpenReport "rptPTOEmpHistAdminN", acViewPreview

End If

Else
If Me.ChkOld = True Then
If IsNull(Me.txtEmpID) Then
MsgBox (" Enter an Employee ID.")
Me.txtEmpID.SetFocus
Exit Sub
Else
DoCmd.OpenReport "rptPTOOldhist", acViewPreview
End If
Else
If Me.chkDate = True Then
If IsNull(Me.txtDateInput) Then
MsgBox (" Enter a date")
Me.txtDateInput.SetFocus
Exit Sub
Else
DoCmd.OpenQuery "qryPTOHistAdminDate",
acViewNormal, acReadOnly
End If
End If
End If
End If
End If
End If
End Sub

Private Sub CmdClose_Click()

DoCmd.OpenForm "frmPTOA", acNormal
DoCmd.Close acForm, "frmPTOEmpHistAdmin"

End Sub

Private Sub Form_Load()

Me.txtEmpID.Value = Null
Me.txtEmpName.Value = Null
Me.chkCurrent = False
Me.ChkOld = False
Me.ChkNegBal = False
Me.chkDate = True
Me.txtDateInput.Enabled = True
Me.txtEmpID.Enabled = False
Me.txtEmpName.Enabled = False
Me.txtDateInput.SetFocus
Me.txtDateInput = Date
End Sub

Private Sub txtEmpID_BeforeUpdate(Cancel As Integer)

If (IsNull(DLookup("[EmpId]", "PTOA", "[EmpID] ='" & Me!txtEmpID &
"'"))) Then
Me!txtEmpName = "EMP not on PTOA table. May be ex-Emp"
Else
Me!txtEmpName = DLookup("[EmpName]", "PTOA", "[EmpID] = '" &
Me!txtEmpID & "'")
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top