Creating a new a record after search

G

Gil

I am noobie at access and vb. I used a text search from
http://www.databasedev.co.uk/text_search.html to create a search in my form.
But I cant figure out how to automatically create a new record if the search
doesnt find any matching records.

Here is my code:

Private Sub cmdSearch_Click()
Dim PhoneRef As String
Dim strSearch As String

'Check txtSearch for Null value or Nill Entry first.

If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------

'Performs the search using value entered into txtSearch
'and evaluates this against values in strStudentID

DoCmd.ShowAllRecords
DoCmd.GoToControl ("Phone")
DoCmd.FindRecord Me!txtSearch

Phone.SetFocus
PhoneRef = Phone.Text
txtSearch.SetFocus
strSearch = txtSearch.Text

'If matching record found sets focus in strStudentID and shows msgbox
'and clears search control

If PhoneRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
Phone.SetFocus
txtSearch = ""

'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try
Again.", _
, "Invalid Search Criterion!"
Phone.SetFocus
Phone = txtSearch.Text
End If
End Sub

Please help!
 
O

Ofer

Hi Gil
Try and add this line
DoCmd.GoToRecord , , acNewRec

On the section where it indicate that no records was found


Else
DoCmd.GoToRecord , , acNewRec
' MsgBox "Match Not Found For: " & strSearch & " - Please Try
Again.", _
' , "Invalid Search Criterion!"
' Phone.SetFocus
' Phone = txtSearch.Text
 
G

Gil

Thanks ofer for all your help You have been my savor. Toda

Ofer said:
Hi Gil
Try and add this line
DoCmd.GoToRecord , , acNewRec

On the section where it indicate that no records was found


Else
DoCmd.GoToRecord , , acNewRec
' MsgBox "Match Not Found For: " & strSearch & " - Please Try
Again.", _
' , "Invalid Search Criterion!"
' Phone.SetFocus
' Phone = txtSearch.Text

--
\\// Live Long and Prosper \\//
BS"D


Gil said:
I am noobie at access and vb. I used a text search from
http://www.databasedev.co.uk/text_search.html to create a search in my form.
But I cant figure out how to automatically create a new record if the search
doesnt find any matching records.

Here is my code:

Private Sub cmdSearch_Click()
Dim PhoneRef As String
Dim strSearch As String

'Check txtSearch for Null value or Nill Entry first.

If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------

'Performs the search using value entered into txtSearch
'and evaluates this against values in strStudentID

DoCmd.ShowAllRecords
DoCmd.GoToControl ("Phone")
DoCmd.FindRecord Me!txtSearch

Phone.SetFocus
PhoneRef = Phone.Text
txtSearch.SetFocus
strSearch = txtSearch.Text

'If matching record found sets focus in strStudentID and shows msgbox
'and clears search control

If PhoneRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
Phone.SetFocus
txtSearch = ""

'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try
Again.", _
, "Invalid Search Criterion!"
Phone.SetFocus
Phone = txtSearch.Text
End If
End Sub

Please help!
 
O

Ofer

Bevakasha

--
\\// Live Long and Prosper \\//
BS"D


Gil said:
Thanks ofer for all your help You have been my savor. Toda

Ofer said:
Hi Gil
Try and add this line
DoCmd.GoToRecord , , acNewRec

On the section where it indicate that no records was found


Else
DoCmd.GoToRecord , , acNewRec
' MsgBox "Match Not Found For: " & strSearch & " - Please Try
Again.", _
' , "Invalid Search Criterion!"
' Phone.SetFocus
' Phone = txtSearch.Text

--
\\// Live Long and Prosper \\//
BS"D


Gil said:
I am noobie at access and vb. I used a text search from
http://www.databasedev.co.uk/text_search.html to create a search in my form.
But I cant figure out how to automatically create a new record if the search
doesnt find any matching records.

Here is my code:

Private Sub cmdSearch_Click()
Dim PhoneRef As String
Dim strSearch As String

'Check txtSearch for Null value or Nill Entry first.

If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------

'Performs the search using value entered into txtSearch
'and evaluates this against values in strStudentID

DoCmd.ShowAllRecords
DoCmd.GoToControl ("Phone")
DoCmd.FindRecord Me!txtSearch

Phone.SetFocus
PhoneRef = Phone.Text
txtSearch.SetFocus
strSearch = txtSearch.Text

'If matching record found sets focus in strStudentID and shows msgbox
'and clears search control

If PhoneRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
Phone.SetFocus
txtSearch = ""

'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try
Again.", _
, "Invalid Search Criterion!"
Phone.SetFocus
Phone = txtSearch.Text
End If
End Sub

Please help!
 

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

Similar Threads


Top