Graham,
I'm back to working on this, and found a piece of code to do something else
i wanted on this form. It works fine in Northwind, but when I add the code to
my form it pop's up dialog looking for input to query on. Kind of like a
parameter query.
I found found the code here.
http://msdn.microsoft.com/archive/d...e/en-us/dnaraccessdev/html/ODC_SynchForms.asp
i added it to Northwind to test it works perfectly. here is the form code.
i will attach as much as i can. cmdorders.click event is where it pops up
this dialog
I cant paste the dialog, but here is the code.
Thanks in advance.
Bob
Option Compare Database
Option Explicit
Private Sub cmdAdd_Click()
Dim testmsg As Integer
testmsg = MsgBox("Do you want to add a record?", 1, "Add Record?")
If testmsg = 1 Then
'Add a new row to the recordset
Me.Recordset.AddNew
Me.Recordset("LastName") = " "
Me.Recordset.Update
'Move to the row that was added
Me.Bookmark = Me.Recordset.Bookmark
Else
End If
End Sub
Private Sub cmdDelete_Click()
Dim intAnswer As Integer
'Ask user if they really want to delete the row
intAnswer = MsgBox("Are You Sure???", _
vbYesNo + vbQuestion, _
"Delete Current Record?")
'If they respond yes, delete the row and
'move to the next row
If intAnswer = vbYes Then
Me.Recordset.Delete
Call cmdNext_Click
Me.Refresh
End If
End Sub
Private Sub cmdExit_Click()
DoCmd.Close
End Sub
Private Sub cmdFind_Click()
'Dim strClientID As String
' Dim varBookmark As Variant
' Dim strHome_Phone_Number As Variant
' Dim strsql As String
'Store the book of the current record
'varBookmark = Me.Recordset.Bookmark
'Attempt to locate another client
'strHome_Phone_Number = InputBox("Enter the Customers Home phone Number
for the Customer you want to locate")
' Dim rst As ADODB.Recordset
' Set rst = New ADODB.Recordset
'strsql = "Select * from tblCustomers WHERE [LastName] =
('strHome_Phone_Number')"
' Establish the connection and cursor type,
' and open active recordset
' rst.ActiveConnection = CurrentProject.Connection
'rst.CursorType = adOpenDynamic
'rst.LockType = adLockOptimistic
'rst.Open "Select * from tblCustomers WHERE [LastName] =
('strHome_Phone_Number')", Options:=adCmdText
' rst.Open "Select * from tblCustomers "
'rst.Open strsql
'With Me.RecordsetClone
'.FindFirst "[Home_Phone] = '" & strHome_Phone_Number & "'"
'.FindFirst "[Home_Phone] = ('strHome_Phone_Number')"
'MsgBox ("I am here")
'If .NoMatch Then
' MsgBox "Home Phone Number " & strHome_Phone_Number & " Not Found!!"
'MsgBox ("Now I am here")
'Else
' Me.Bookmark = .Bookmark
'MsgBox ("No I really here")
'End If
'End With
'Me.Recordset.Find "LastName = " & 'strHome_Phone_Number', Start:=1
'If client not found, display a message and return to
'the original record
' If Me.Recordset.EOF Then
' MsgBox "Home Phone Number " & strHome_Phone_Number & " Not Found!!"
' Me.Recordset.Bookmark = varBookmark
'If client found, synchronize the form with the
'underlying recordset
' Else
' Me.Bookmark = Me.Recordset.Bookmark
'End If
'End Sub
'this section was removed to add a home made input box for the phone number
please see frmSearchPhone
'Private Sub cmdFind_Click()
' Dim strHome_Phone_Number As String
' Dim rsc As ADODB.Recordset
' strHome_Phone_Number = InputBox( _
' "Enter the Home phone Number for the Customer you want to locate")
'Set rsc = Me.RecordsetClone
'With rsc
' .MoveFirst
' .Find "[Home_Phone] = '" & strHome_Phone_Number & "'"
' If .EOF Then
' MsgBox "Home Phone Number " & strHome_Phone_Number & " Not
Found!!"
' Else
' Me.Bookmark = .Bookmark
'End If
'End With
'Set rsc = Nothing
'This section was added to call frmsearchphone
DoCmd.OpenForm "frmSearchPhone", WindowMode:=acDialog
End Sub
Private Sub cmdNext_Click()
'Move to the next record in the recordset
Me.Recordset.MoveNext
'If at EOF, move to the previous record
If Me.Recordset.EOF Then
Me.Recordset.MovePrevious
MsgBox "Already at Last Record!!"
End If
'Set the bookmark of the form to the bookmark
'of the recordset underlying the form
Me.Bookmark = Me.Recordset.Bookmark
End Sub
Private Sub cmdOrders_Click()
Dim strWhereCond
strWhereCond = "ID = Forms!frmCustomers_info!ID"
DoCmd.OpenForm "tblCustomers_orders_Query",
wherecondition:=strWhereCond
'strWhereCond = "ID = Forms!frm_Customerinfo!ID"
'DoCmd.OpenForm "tblCustomers_orders_Query", wherecondition:=strWhereCond
End Sub
Private Sub cmdPrevious_Click()
'Move to the next record in the recordset
Me.Recordset.MovePrevious
'If at BOF, move to the next record
If Me.Recordset.BOF Then
Me.Recordset.MoveNext
MsgBox "Already at First Record!!"
End If
'Set the bookmark of the form to the bookmark
'of the recordset underlying the form
Me.Bookmark = Me.Recordset.Bookmark
End Sub
'Private Sub Form_Current()
' Dim strWhereCond
' strWhereCond = "ID = Forms!frm_Customerinfo!ID"
' 'strWhereCond = "CustomerID = Forms!Customers!CustomerID"
'If IsLoaded("tblCustomers_orders_Query") Then
' DoCmd.OpenForm "tblCustomers_orders_Query",
wherecondition:=strWhereCond
'End If
'End Sub
Private Sub Form_Load()
'Declare and instantiate a recordset
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
'Establish the Connection, Cursor Type, and
'Lock Type and open the recordset
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenDynamic
rst.CursorLocation = adUseClient
rst.LockType = adLockOptimistic
rst.Open "Select * from tblCustomers", Options:=adCmdText
'Set the form's recordset to the recordset just created
Set Me.Recordset = rst
End Sub
Graham Mandeno said:
Hi Robert
Probably the most elegant way around this is to create your own InputBox.
(I always avoid InputBox anyway, except for something quick and dirty,
because it's limited and ugly.)
Create a small unbound form (frmSearchPhone) with a textbox for the phone
number (txtSearchPhone) and use the same input mask as you have for the
actual field. Add two buttons - cmdFind and cmdCancel - and set the Default
property of the first and the Cancel property of the second.
Turn off all the default stuff like record selectors and navigation buttons
and control menu.
For cmdCancel, simply close the current form:
DoCmd.Close acForm, Me.Name
Use the same code as below for cmdFind, with the following changes:
Private Sub cmdFind_Click()
Dim frm as Form
Dim rsc As ADODB.Recordset
Set frm = Forms("name of your main form")
Set rsc = frm.RecordsetClone
With rsc
.MoveFirst
.Find "[Home_Phone] = '" & txtSearchPhone & "'"
If .EOF Then
MsgBox "Home Phone Number " & txtSearchPhone & " Not Found!!"
txtSearchPhone.SetFocus
Else
frm.Bookmark = .Bookmark
DoCmd.Close acForm, Me.Name
End If
End With
Set rsc = Nothing
Set frm = Nothing
End Sub
On your main form, all the command button needs to do is open the new form
modally:
DoCmd.OpenForm "frmSearchPhone", WindowMode:=acDialog
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
"(e-mail address removed)"
Graham,
You are a genius. Thank you for your help. I was really stumped. I now
have
a supplemental question. I have to figure out how to input the find. I am
using an Input mask, and so teh data looks like this (203) 334-9086 when i
just search for the numbers it fails to find a match. If i input it as
(203)
334-9086 it works. How do I get around this?
Thanks in advance???
Bob Smith
Graham Mandeno said:
Hi Robert
You didn't answer my question about whether this is an MDB or an ADP. I
am
now assuming the latter.
This means that the form's Recordset and RecordsetClone properties will
be
ADODB Recordsets, not DAO Recordsets. The two objects have markedly
different properties and methods. Specifically, the differences that are
pertinent to your code are:
1. DAO has a FindFirst method, while with ADO you must use MoveFirst
followed by Find.
2. DAO has a NoMatch property, while with ADO you must use EOF.
3. With ADO, each reference to RecordsetClone returns a new instance,
while
with DAO each reference returns the same instance. Therefore with ADO
you
must assign the RecordsetClone to a Recordset variable.
So, your code should look like this:
Private Sub cmdFind_Click()
Dim strHome_Phone_Number As String
Dim rsc As ADODB.Recordset
strHome_Phone_Number = InputBox( _
"Enter the Home phone Number for the Customer you want to
locate")
Set rsc = Me.RecordsetClone
With rsc
.MoveFirst
.Find "[Home_Phone] = '" & strHome_Phone_Number & "'"
If .EOF Then
MsgBox "Home Phone Number " & strHome_Phone_Number & " Not
Found!!"
Else
Me.Bookmark = .Bookmark
End If
End With
Set rsc = Nothing
End Sub
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand