Walshie1987
Technical User
- Oct 5, 2006
- 100
Hi, I'm wanting to create a simple db so when i enter a document number, if the document number is in the record a box will say something like "found" then go to the record. If the record isn't found then i want a box the say something like "record not found, add now?" then open an input form.
I've managed to come up with this (see below) but when the record is there the box says record found, then opens the "add new record" box, and if i enter a number not in the db then it just goes to the first record and then brings the "add new record" box up. I wondered if anyone could help,
txtSearch = Search box
ReqNumber = Document Number
frmInput = Input Form (add new form)
Main = Name of Table
Here's the code:
Private Sub cmdSearch_Click()
Dim ReqNumberRef As String
Dim txtSearch As String
'Check Search Box for Blank Value
If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please Enter Req Number!", vbOKOnly, "No Req Number"
Me![txtSearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Searches for record
DoCmd.ShowAllRecords
DoCmd.GoToControl ("ReqNumber")
DoCmd.FindRecord Me!txtSearch
ReqNumber.SetFocus
txtSearch = ReqNumber.Text
ReqNumber.SetFocus
'If Req Number found goes to record
If ReqNumber = txtSearch Then
MsgBox "Req Found: " & txtSearch, , "Congratulations!"
ReqNumber.SetFocus
txtSearch = ""
'If Req Number not found goes to input sheet
If Not ReqNumber = txtSearch Then
UserSelection = MsgBox("Req Not Found" & Chr(10) & "Add Req", vbYesNo)
Select Case UserSelection
Case 6
DoCmd.OpenForm "frmInput"
Case 7
End Select
End If
End If
Me![txtSearch] = Null
End Sub
Thanks alot
I've managed to come up with this (see below) but when the record is there the box says record found, then opens the "add new record" box, and if i enter a number not in the db then it just goes to the first record and then brings the "add new record" box up. I wondered if anyone could help,
txtSearch = Search box
ReqNumber = Document Number
frmInput = Input Form (add new form)
Main = Name of Table
Here's the code:
Private Sub cmdSearch_Click()
Dim ReqNumberRef As String
Dim txtSearch As String
'Check Search Box for Blank Value
If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please Enter Req Number!", vbOKOnly, "No Req Number"
Me![txtSearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Searches for record
DoCmd.ShowAllRecords
DoCmd.GoToControl ("ReqNumber")
DoCmd.FindRecord Me!txtSearch
ReqNumber.SetFocus
txtSearch = ReqNumber.Text
ReqNumber.SetFocus
'If Req Number found goes to record
If ReqNumber = txtSearch Then
MsgBox "Req Found: " & txtSearch, , "Congratulations!"
ReqNumber.SetFocus
txtSearch = ""
'If Req Number not found goes to input sheet
If Not ReqNumber = txtSearch Then
UserSelection = MsgBox("Req Not Found" & Chr(10) & "Add Req", vbYesNo)
Select Case UserSelection
Case 6
DoCmd.OpenForm "frmInput"
Case 7
End Select
End If
End If
Me![txtSearch] = Null
End Sub
Thanks alot