Searching Records

G

Guest

I have a db that designed I actively work in. I created the table and form.
When my staff wants to search for a record, they have the form open, click
the field, do ctrl f to find it. The problem I am having is that they are
not watching what they are doing and type over existing data. I created
another form for "searching". How do I get this form to open in a search
capacity and then bring up the actual record in edit mode? They will search
by ssn, name, acct number or case. Please help. I am a beginner/novice user.
 
T

tina

a common solution is to create an unbound form and add controls that will be
used to enter search criteria, such as txtSSN, txtName, txtAcct, txtCase.
i'll call the form, frmMain. then, in Design view, add a subform control
from the Toolbox toolbar. i'll call the subform control ChildData. set the
control's SourceObject property to the name of the data entry form that
you've already built. make sure that the LinkChildFields and
LinkMasterFields properties are *blank*. size the subform control so it's
big enough to show the entire data entry form inside it - you'll have to
change the size in Design view, then open frmMain in Form view to see if you
need to adjust it.

open the data entry form in Design view. in the RecordSource property, click
the Build button at the right side (...), it will open a window that looks
like a query design view. add all the fields to the design grid. go to the
column that has the fieldname for the ssn data. add criteria to that field,
as

[Forms]![frmMain]![txtSSN] Or [Forms]![frmMain]![txtSSN] Is Null

go to the column that has the fieldname for the name data. add criteria to
that field, as

[Forms]![frmMain]![txtName] Or [Forms]![frmMain]![txtName] Is Null

repeat for the acct number and case fields. close the window and save the
form. back in frmMain's Design view, add a command button and add code to
its' Click event procedure, as

Me!ChildData.Form.Requery

now, when you open frmMain, all the records will be available in the
subform. to find a specific record, enter a value in one or more of the
"search" controls, and then click the command button to requery the
subform's RecordSource.

hth
 
G

Guest

Hi Jana,

You may already know this. If you want to disable editing of an individual
text box or form control, click on the control, open the properties sheet,
click on the Data tab, and changed Locked from No to Yes. They can see the
information but they cannot edit its contents.

I would use unbound combo boxes for them to search with. Here is some code
that I use with a combo box on one form to open other forms to the record I
want.

I am capitalizing parts of the code that you will need to edit.

Private Sub cboOpenToMyRecord_AfterUpdate()
Dim strCbo As Long
strCbo = Me!CBOOPENTOMYRECORD

DoCmd.OpenForm "MYFORMNAME"
Forms!MYFORMNAME![MYPRIMARYKEYFIELDFORMCONTROLNAME].SetFocus
DoCmd.FindRecord (strCbo)
End Sub

MYPRIMARYKEYFIELDFORMCONTROLNAME is the name of the text box or combo box
which shows your table's Primary Key field. It would be something like
CustomerID, txtEmployeeID, cboWorkOrderID, etc.

To allow them to enter new records only you change the code to this:
DoCmd.OpenForm "MYFORMNAME", , , ,acFormAdd

To disable all editing in the form that opens you change the code to this:
DoCmd.OpenForm "MYFORMNAME", , , ,acFormReadOnly


You can let them open queries in read only mode with this code:

DoCmd.OpenQuery "myqueryname", , acReadOnly


I wish you success.
Hunter57
Just huntin' for some data.
http://churchmanagementsoftware.googlepages.com
 
G

Guest

Hunter57:

I do not know how to write code. I dont guess I know how the combo boxes
work. I have tried changing the properties, however, when I changed it, it
would not let me add a record in add mode. Your suggestions are appreciated.
--
Jana


Hunter57 said:
Hi Jana,

You may already know this. If you want to disable editing of an individual
text box or form control, click on the control, open the properties sheet,
click on the Data tab, and changed Locked from No to Yes. They can see the
information but they cannot edit its contents.

I would use unbound combo boxes for them to search with. Here is some code
that I use with a combo box on one form to open other forms to the record I
want.

I am capitalizing parts of the code that you will need to edit.

Private Sub cboOpenToMyRecord_AfterUpdate()
Dim strCbo As Long
strCbo = Me!CBOOPENTOMYRECORD

DoCmd.OpenForm "MYFORMNAME"
Forms!MYFORMNAME![MYPRIMARYKEYFIELDFORMCONTROLNAME].SetFocus
DoCmd.FindRecord (strCbo)
End Sub

MYPRIMARYKEYFIELDFORMCONTROLNAME is the name of the text box or combo box
which shows your table's Primary Key field. It would be something like
CustomerID, txtEmployeeID, cboWorkOrderID, etc.

To allow them to enter new records only you change the code to this:
DoCmd.OpenForm "MYFORMNAME", , , ,acFormAdd

To disable all editing in the form that opens you change the code to this:
DoCmd.OpenForm "MYFORMNAME", , , ,acFormReadOnly


You can let them open queries in read only mode with this code:

DoCmd.OpenQuery "myqueryname", , acReadOnly


I wish you success.
Hunter57
Just huntin' for some data.
http://churchmanagementsoftware.googlepages.com

Jana said:
I have a db that designed I actively work in. I created the table and form.
When my staff wants to search for a record, they have the form open, click
the field, do ctrl f to find it. The problem I am having is that they are
not watching what they are doing and type over existing data. I created
another form for "searching". How do I get this form to open in a search
capacity and then bring up the actual record in edit mode? They will search
by ssn, name, acct number or case. Please help. I am a beginner/novice user.
 
G

Guest

Hi Jana,
I created form1 and form2. Where the records source for form1 is my table
(all data). form2 I am using to ask the user for a loan #. When I open form2
(in form view) I am unable to input a loan number in the "enter loan no"
combo box I created.

I named my Unbound combo box cboOpenToMyRecord_AfterUpdate
Control source is blank
row source is table/query
After update = cboOpenToMyRecord_AfterUpdate()


What am I doing wrong? Here is my code

Option Compare Database
Option Explicit


Private Sub cboOpenToMyRecord_AfterUpdate()
Dim strCbo As Long
strCbo = Me!cboOpenToMyRecord_AfterUpdate

DoCmd.OpenForm "form1", , , , acFormAdd
Forms!form1![loan#].SetFocus
DoCmd.FindRecord (strCbo)
End Sub


Jana said:
Hunter57:

I do not know how to write code. I dont guess I know how the combo boxes
work. I have tried changing the properties, however, when I changed it, it
would not let me add a record in add mode. Your suggestions are appreciated.
--
Jana


Hunter57 said:
Hi Jana,

You may already know this. If you want to disable editing of an individual
text box or form control, click on the control, open the properties sheet,
click on the Data tab, and changed Locked from No to Yes. They can see the
information but they cannot edit its contents.

I would use unbound combo boxes for them to search with. Here is some code
that I use with a combo box on one form to open other forms to the record I
want.

I am capitalizing parts of the code that you will need to edit.

Private Sub cboOpenToMyRecord_AfterUpdate()
Dim strCbo As Long
strCbo = Me!CBOOPENTOMYRECORD

DoCmd.OpenForm "MYFORMNAME"
Forms!MYFORMNAME![MYPRIMARYKEYFIELDFORMCONTROLNAME].SetFocus
DoCmd.FindRecord (strCbo)
End Sub

MYPRIMARYKEYFIELDFORMCONTROLNAME is the name of the text box or combo box
which shows your table's Primary Key field. It would be something like
CustomerID, txtEmployeeID, cboWorkOrderID, etc.

To allow them to enter new records only you change the code to this:
DoCmd.OpenForm "MYFORMNAME", , , ,acFormAdd

To disable all editing in the form that opens you change the code to this:
DoCmd.OpenForm "MYFORMNAME", , , ,acFormReadOnly


You can let them open queries in read only mode with this code:

DoCmd.OpenQuery "myqueryname", , acReadOnly


I wish you success.
Hunter57
Just huntin' for some data.
http://churchmanagementsoftware.googlepages.com

Jana said:
I have a db that designed I actively work in. I created the table and form.
When my staff wants to search for a record, they have the form open, click
the field, do ctrl f to find it. The problem I am having is that they are
not watching what they are doing and type over existing data. I created
another form for "searching". How do I get this form to open in a search
capacity and then bring up the actual record in edit mode? They will search
by ssn, name, acct number or case. Please help. I am a beginner/novice user.
 
G

Guest

Hi LaRana,

First, Using the # symbol in a field can cause problems. The # symbol is an
Access Reserved Character that lets Access know that you are using a date.
It is used like this: #6/23/2007# This is so that Access can recognize that
as a date and not just a number.

It would be a good idea if you can change Loan# to LoanNo or LoanNumber or
LoanID in your tables and your forms.

Back to why your code does not work:

In your code you have Form1 opening in Data entry mode (that is what the ",
, , , acformAdd" does). All you can do is enter new records.

The problem is your code is also trying to find a record and open to it:
"DoCmd.FindRecord (strCbo)". This is not possible when you open the form in
Data Entry Mode using ", , , , acFormAdd".

If you remove the ", , , , acFormAdd" you should be able to go to the record
you desire if it exists. Your OpenToMyRecord combo box must be unbound for
that.

If you remove the "DoCmd.FindRecord (strCbo)" you can add new records to
your database. But your Loan# will not automatically be added.

________________________
If you are trying to add a New Loan Number to your Database automatically I
recommend using the "not in list" event of your combo box.

First, delete the ", , , , acFormAdd" part of your code. This way if the
loan number already exists you can open your form to that loan.

On Form 2 where your OpenToMyRecord combo box is with the new loan number:

1) Make sure that Loan# (and not some other field) is the bound column in
your combo Box query. (if you are not sure how to do this, just let us know
and we can help.)

2) On the Properties sheet of the combo box select the Data tab and change
the "Limit to List" property to Yes.

3) Place this code in the NotInList event of your OpenToMyRecord Combo Box
in Form2 (Change YOURTABLENAME to the name of your table):


Private Sub cboOpenToMyRecord_NotInList(NewData As String, Response As
Integer)

Dim Result
Dim Msg As String
Dim CR As String

CR = Chr$(13)

' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

Select Case MsgBox(" '" & NewData & "' is not in the list." _
& vbCrLf & "" _
& vbCrLf & "Do you want to add '" & NewData & "' to the list?" _
, vbYesNoCancel Or vbQuestion Or vbSystemModal Or _
vbDefaultButton1, " Add Entry To List?")

Case vbYes

' If the user chose Yes, start Form1 in data entry
' mode as a dialog form, passing the new Loan# in
' NewData to the OpenForm method's OpenArgs argument.

DoCmd.OpenForm "Form1", , , , acAdd, acDialog, _
NewData & Me.cboOpenToMyRecord


' Look for the Loan# the user created in Form1.
Result = DLookup("[Loan#]", "YOURTABLENAME", _
"[Loan#] = '" & NewData & "'")
If IsNull(Result) Then
' If the Loan# was not created, set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again!"
Else
' If the Loan# was created, set the Response argument to
' indicate that new data is being added.
Response = acDataErrAdded
End If

'Return to the list
Case vbNo
' If the user selected no set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue

Case vbCancel
' If the user selected no set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
'Delete the entry in the ComboBox
Me!cboOpenToMyRecord = Null

End Select

End Sub

4) ADD THIS CODE TO FORM1:
Private Sub Form_Open(Cancel As Integer)
If Len(Me.OpenArgs) > 0 Then
DoCmd.GoToRecord acForm, "Form1", acNewRec
Me![Loan#] = Me.OpenArgs
Else: DoCmd.GoToRecord acForm, "Form1", acNewRec
End If

End Sub


For more information and different ways of using this event you can do a
google search and find many tutorials and code samples on how to do that.
There are a number of different varieties of the "not in list" event examples
so I suggest you search until you find one that will do what you want and
that you are able to use. Some of them require a lot of coding and others
not so much.


Hope it helps,

Hunter57
http://churchmanagementsoftware.googlepages.com



LaRana said:
Hi Jana,
I created form1 and form2. Where the records source for form1 is my table
(all data). form2 I am using to ask the user for a loan #. When I open form2
(in form view) I am unable to input a loan number in the "enter loan no"
combo box I created.

I named my Unbound combo box cboOpenToMyRecord_AfterUpdate
Control source is blank
row source is table/query
After update = cboOpenToMyRecord_AfterUpdate()


What am I doing wrong? Here is my code

Option Compare Database
Option Explicit


Private Sub cboOpenToMyRecord_AfterUpdate()
Dim strCbo As Long
strCbo = Me!cboOpenToMyRecord_AfterUpdate

DoCmd.OpenForm "form1", , , , acFormAdd
Forms!form1![loan#].SetFocus
DoCmd.FindRecord (strCbo)
End Sub


Jana said:
Hunter57:

I do not know how to write code. I dont guess I know how the combo boxes
work. I have tried changing the properties, however, when I changed it, it
would not let me add a record in add mode. Your suggestions are appreciated.
--
Jana


Hunter57 said:
Hi Jana,

You may already know this. If you want to disable editing of an individual
text box or form control, click on the control, open the properties sheet,
click on the Data tab, and changed Locked from No to Yes. They can see the
information but they cannot edit its contents.

I would use unbound combo boxes for them to search with. Here is some code
that I use with a combo box on one form to open other forms to the record I
want.

I am capitalizing parts of the code that you will need to edit.

Private Sub cboOpenToMyRecord_AfterUpdate()
Dim strCbo As Long
strCbo = Me!CBOOPENTOMYRECORD

DoCmd.OpenForm "MYFORMNAME"
Forms!MYFORMNAME![MYPRIMARYKEYFIELDFORMCONTROLNAME].SetFocus
DoCmd.FindRecord (strCbo)
End Sub

MYPRIMARYKEYFIELDFORMCONTROLNAME is the name of the text box or combo box
which shows your table's Primary Key field. It would be something like
CustomerID, txtEmployeeID, cboWorkOrderID, etc.

To allow them to enter new records only you change the code to this:
DoCmd.OpenForm "MYFORMNAME", , , ,acFormAdd

To disable all editing in the form that opens you change the code to this:
DoCmd.OpenForm "MYFORMNAME", , , ,acFormReadOnly


You can let them open queries in read only mode with this code:

DoCmd.OpenQuery "myqueryname", , acReadOnly


I wish you success.
Hunter57
Just huntin' for some data.
http://churchmanagementsoftware.googlepages.com

:

I have a db that designed I actively work in. I created the table and form.
When my staff wants to search for a record, they have the form open, click
the field, do ctrl f to find it. The problem I am having is that they are
not watching what they are doing and type over existing data. I created
another form for "searching". How do I get this form to open in a search
capacity and then bring up the actual record in edit mode? They will search
by ssn, name, acct number or case. Please help. I am a beginner/novice user.
 
G

Guest

Ok here are the questions:
a) can you explain how to do # 1? I want to be sure it is what you mean.

Can we start all over?: ( assume I have two forms form1 and form2 with no
code at all)
form1:
has one combo box where I would the user to input a loan number. Upon input,
another form (form2) displays 3 data fields.

form 2: 3 fields including loan number and other two.

Would you please explain what code to place on form1 and what properties.
Same for form2. Also, what I should name each form so that the code works
w/out any trouble.

I am sorry... I am a little confused here...


Hunter57 said:
Hi LaRana,

First, Using the # symbol in a field can cause problems. The # symbol is an
Access Reserved Character that lets Access know that you are using a date.
It is used like this: #6/23/2007# This is so that Access can recognize that
as a date and not just a number.

It would be a good idea if you can change Loan# to LoanNo or LoanNumber or
LoanID in your tables and your forms.

Back to why your code does not work:

In your code you have Form1 opening in Data entry mode (that is what the ",
, , , acformAdd" does). All you can do is enter new records.

The problem is your code is also trying to find a record and open to it:
"DoCmd.FindRecord (strCbo)". This is not possible when you open the form in
Data Entry Mode using ", , , , acFormAdd".

If you remove the ", , , , acFormAdd" you should be able to go to the record
you desire if it exists. Your OpenToMyRecord combo box must be unbound for
that.

If you remove the "DoCmd.FindRecord (strCbo)" you can add new records to
your database. But your Loan# will not automatically be added.

________________________
If you are trying to add a New Loan Number to your Database automatically I
recommend using the "not in list" event of your combo box.

First, delete the ", , , , acFormAdd" part of your code. This way if the
loan number already exists you can open your form to that loan.

On Form 2 where your OpenToMyRecord combo box is with the new loan number:

1) Make sure that Loan# (and not some other field) is the bound column in
your combo Box query. (if you are not sure how to do this, just let us know
and we can help.)

2) On the Properties sheet of the combo box select the Data tab and change
the "Limit to List" property to Yes.

3) Place this code in the NotInList event of your OpenToMyRecord Combo Box
in Form2 (Change YOURTABLENAME to the name of your table):


Private Sub cboOpenToMyRecord_NotInList(NewData As String, Response As
Integer)

Dim Result
Dim Msg As String
Dim CR As String

CR = Chr$(13)

' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

Select Case MsgBox(" '" & NewData & "' is not in the list." _
& vbCrLf & "" _
& vbCrLf & "Do you want to add '" & NewData & "' to the list?" _
, vbYesNoCancel Or vbQuestion Or vbSystemModal Or _
vbDefaultButton1, " Add Entry To List?")

Case vbYes

' If the user chose Yes, start Form1 in data entry
' mode as a dialog form, passing the new Loan# in
' NewData to the OpenForm method's OpenArgs argument.

DoCmd.OpenForm "Form1", , , , acAdd, acDialog, _
NewData & Me.cboOpenToMyRecord


' Look for the Loan# the user created in Form1.
Result = DLookup("[Loan#]", "YOURTABLENAME", _
"[Loan#] = '" & NewData & "'")
If IsNull(Result) Then
' If the Loan# was not created, set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again!"
Else
' If the Loan# was created, set the Response argument to
' indicate that new data is being added.
Response = acDataErrAdded
End If

'Return to the list
Case vbNo
' If the user selected no set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue

Case vbCancel
' If the user selected no set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
'Delete the entry in the ComboBox
Me!cboOpenToMyRecord = Null

End Select

End Sub

4) ADD THIS CODE TO FORM1:
Private Sub Form_Open(Cancel As Integer)
If Len(Me.OpenArgs) > 0 Then
DoCmd.GoToRecord acForm, "Form1", acNewRec
Me![Loan#] = Me.OpenArgs
Else: DoCmd.GoToRecord acForm, "Form1", acNewRec
End If

End Sub


For more information and different ways of using this event you can do a
google search and find many tutorials and code samples on how to do that.
There are a number of different varieties of the "not in list" event examples
so I suggest you search until you find one that will do what you want and
that you are able to use. Some of them require a lot of coding and others
not so much.


Hope it helps,

Hunter57
http://churchmanagementsoftware.googlepages.com



LaRana said:
Hi Jana,
I created form1 and form2. Where the records source for form1 is my table
(all data). form2 I am using to ask the user for a loan #. When I open form2
(in form view) I am unable to input a loan number in the "enter loan no"
combo box I created.

I named my Unbound combo box cboOpenToMyRecord_AfterUpdate
Control source is blank
row source is table/query
After update = cboOpenToMyRecord_AfterUpdate()


What am I doing wrong? Here is my code

Option Compare Database
Option Explicit


Private Sub cboOpenToMyRecord_AfterUpdate()
Dim strCbo As Long
strCbo = Me!cboOpenToMyRecord_AfterUpdate

DoCmd.OpenForm "form1", , , , acFormAdd
Forms!form1![loan#].SetFocus
DoCmd.FindRecord (strCbo)
End Sub


Jana said:
Hunter57:

I do not know how to write code. I dont guess I know how the combo boxes
work. I have tried changing the properties, however, when I changed it, it
would not let me add a record in add mode. Your suggestions are appreciated.
--
Jana


:

Hi Jana,

You may already know this. If you want to disable editing of an individual
text box or form control, click on the control, open the properties sheet,
click on the Data tab, and changed Locked from No to Yes. They can see the
information but they cannot edit its contents.

I would use unbound combo boxes for them to search with. Here is some code
that I use with a combo box on one form to open other forms to the record I
want.

I am capitalizing parts of the code that you will need to edit.

Private Sub cboOpenToMyRecord_AfterUpdate()
Dim strCbo As Long
strCbo = Me!CBOOPENTOMYRECORD

DoCmd.OpenForm "MYFORMNAME"
Forms!MYFORMNAME![MYPRIMARYKEYFIELDFORMCONTROLNAME].SetFocus
DoCmd.FindRecord (strCbo)
End Sub

MYPRIMARYKEYFIELDFORMCONTROLNAME is the name of the text box or combo box
which shows your table's Primary Key field. It would be something like
CustomerID, txtEmployeeID, cboWorkOrderID, etc.

To allow them to enter new records only you change the code to this:
DoCmd.OpenForm "MYFORMNAME", , , ,acFormAdd

To disable all editing in the form that opens you change the code to this:
DoCmd.OpenForm "MYFORMNAME", , , ,acFormReadOnly


You can let them open queries in read only mode with this code:

DoCmd.OpenQuery "myqueryname", , acReadOnly


I wish you success.
Hunter57
Just huntin' for some data.
http://churchmanagementsoftware.googlepages.com

:

I have a db that designed I actively work in. I created the table and form.
When my staff wants to search for a record, they have the form open, click
the field, do ctrl f to find it. The problem I am having is that they are
not watching what they are doing and type over existing data. I created
another form for "searching". How do I get this form to open in a search
capacity and then bring up the actual record in edit mode? They will search
by ssn, name, acct number or case. Please help. I am a beginner/novice user.
 
G

Guest

Hi LaRana,

Don't feel bad, I'm confused too!

I. Before I can help you I need to know what it is you are trying to
accomplish. Please select one of the following.

1) I am trying to find an existing account or record.

2) I am trying to find and edit an existing account or record.

3) I am trying to add a new account or record to the database.

4). Other--Please explain.


II. About your question about names. It does not matter much what you name
your forms unless you use a word Reserved by Access for special purposes. It
also helps to leave no spaces in your table, field, form, textbox, and
combobox names. You can name them like this if you want: Loan_Form,
Accounts_Form, New_Accounts, etc.

It is a good idea too use names that descibe the object or its purpose. If
the table is about loans the Loans or tblLoans is a good name. If the
purpose of a form is to add new Accounts the NewAccountsForm or
frmNewAccounts are a couple of examples you can use.


III. Since you do not know how to write code see no alternative that to
write the code for you. In order to do this I will need to know the names of
your tables, fields, textboxes, and comboboxes. If this is against company
policy you can use Aliases and then just replace the aliases with the real
names after I write the code.

Please provide the information in this Format:

Tables: TableName
FieldNames:

FieldName1
FieldName2
FieldName3
etc.

Forms: FormName
ControlName:

TextBoxName1
TextBoxName2
ComboBoxName1
etc.

You can email me at pwood57 at gmail dot com. (I use this format to avoid
spam)
Or you can click on the link below, go to my Contact page and send me your
information.

Regards:
Hunter57
http://churchmanagementsoftware.googlepages.com



LaRana said:
Ok here are the questions:
a) can you explain how to do # 1? I want to be sure it is what you mean.

Can we start all over?: ( assume I have two forms form1 and form2 with no
code at all)
form1:
has one combo box where I would the user to input a loan number. Upon input,
another form (form2) displays 3 data fields.

form 2: 3 fields including loan number and other two.

Would you please explain what code to place on form1 and what properties.
Same for form2. Also, what I should name each form so that the code works
w/out any trouble.

I am sorry... I am a little confused here...


Hunter57 said:
Hi LaRana,

First, Using the # symbol in a field can cause problems. The # symbol is an
Access Reserved Character that lets Access know that you are using a date.
It is used like this: #6/23/2007# This is so that Access can recognize that
as a date and not just a number.

It would be a good idea if you can change Loan# to LoanNo or LoanNumber or
LoanID in your tables and your forms.

Back to why your code does not work:

In your code you have Form1 opening in Data entry mode (that is what the ",
, , , acformAdd" does). All you can do is enter new records.

The problem is your code is also trying to find a record and open to it:
"DoCmd.FindRecord (strCbo)". This is not possible when you open the form in
Data Entry Mode using ", , , , acFormAdd".

If you remove the ", , , , acFormAdd" you should be able to go to the record
you desire if it exists. Your OpenToMyRecord combo box must be unbound for
that.

If you remove the "DoCmd.FindRecord (strCbo)" you can add new records to
your database. But your Loan# will not automatically be added.

________________________
If you are trying to add a New Loan Number to your Database automatically I
recommend using the "not in list" event of your combo box.

First, delete the ", , , , acFormAdd" part of your code. This way if the
loan number already exists you can open your form to that loan.

On Form 2 where your OpenToMyRecord combo box is with the new loan number:

1) Make sure that Loan# (and not some other field) is the bound column in
your combo Box query. (if you are not sure how to do this, just let us know
and we can help.)

2) On the Properties sheet of the combo box select the Data tab and change
the "Limit to List" property to Yes.

3) Place this code in the NotInList event of your OpenToMyRecord Combo Box
in Form2 (Change YOURTABLENAME to the name of your table):


Private Sub cboOpenToMyRecord_NotInList(NewData As String, Response As
Integer)

Dim Result
Dim Msg As String
Dim CR As String

CR = Chr$(13)

' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

Select Case MsgBox(" '" & NewData & "' is not in the list." _
& vbCrLf & "" _
& vbCrLf & "Do you want to add '" & NewData & "' to the list?" _
, vbYesNoCancel Or vbQuestion Or vbSystemModal Or _
vbDefaultButton1, " Add Entry To List?")

Case vbYes

' If the user chose Yes, start Form1 in data entry
' mode as a dialog form, passing the new Loan# in
' NewData to the OpenForm method's OpenArgs argument.

DoCmd.OpenForm "Form1", , , , acAdd, acDialog, _
NewData & Me.cboOpenToMyRecord


' Look for the Loan# the user created in Form1.
Result = DLookup("[Loan#]", "YOURTABLENAME", _
"[Loan#] = '" & NewData & "'")
If IsNull(Result) Then
' If the Loan# was not created, set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again!"
Else
' If the Loan# was created, set the Response argument to
' indicate that new data is being added.
Response = acDataErrAdded
End If

'Return to the list
Case vbNo
' If the user selected no set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue

Case vbCancel
' If the user selected no set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
'Delete the entry in the ComboBox
Me!cboOpenToMyRecord = Null

End Select

End Sub

4) ADD THIS CODE TO FORM1:
Private Sub Form_Open(Cancel As Integer)
If Len(Me.OpenArgs) > 0 Then
DoCmd.GoToRecord acForm, "Form1", acNewRec
Me![Loan#] = Me.OpenArgs
Else: DoCmd.GoToRecord acForm, "Form1", acNewRec
End If

End Sub


For more information and different ways of using this event you can do a
google search and find many tutorials and code samples on how to do that.
There are a number of different varieties of the "not in list" event examples
so I suggest you search until you find one that will do what you want and
that you are able to use. Some of them require a lot of coding and others
not so much.


Hope it helps,

Hunter57
http://churchmanagementsoftware.googlepages.com



LaRana said:
Hi Jana,
I created form1 and form2. Where the records source for form1 is my table
(all data). form2 I am using to ask the user for a loan #. When I open form2
(in form view) I am unable to input a loan number in the "enter loan no"
combo box I created.

I named my Unbound combo box cboOpenToMyRecord_AfterUpdate
Control source is blank
row source is table/query
After update = cboOpenToMyRecord_AfterUpdate()


What am I doing wrong? Here is my code

Option Compare Database
Option Explicit


Private Sub cboOpenToMyRecord_AfterUpdate()
Dim strCbo As Long
strCbo = Me!cboOpenToMyRecord_AfterUpdate

DoCmd.OpenForm "form1", , , , acFormAdd
Forms!form1![loan#].SetFocus
DoCmd.FindRecord (strCbo)
End Sub


:

Hunter57:

I do not know how to write code. I dont guess I know how the combo boxes
work. I have tried changing the properties, however, when I changed it, it
would not let me add a record in add mode. Your suggestions are appreciated.
--
Jana


:

Hi Jana,

You may already know this. If you want to disable editing of an individual
text box or form control, click on the control, open the properties sheet,
click on the Data tab, and changed Locked from No to Yes. They can see the
information but they cannot edit its contents.

I would use unbound combo boxes for them to search with. Here is some code
that I use with a combo box on one form to open other forms to the record I
want.

I am capitalizing parts of the code that you will need to edit.

Private Sub cboOpenToMyRecord_AfterUpdate()
Dim strCbo As Long
strCbo = Me!CBOOPENTOMYRECORD

DoCmd.OpenForm "MYFORMNAME"
Forms!MYFORMNAME![MYPRIMARYKEYFIELDFORMCONTROLNAME].SetFocus
DoCmd.FindRecord (strCbo)
End Sub

MYPRIMARYKEYFIELDFORMCONTROLNAME is the name of the text box or combo box
which shows your table's Primary Key field. It would be something like
CustomerID, txtEmployeeID, cboWorkOrderID, etc.

To allow them to enter new records only you change the code to this:
DoCmd.OpenForm "MYFORMNAME", , , ,acFormAdd

To disable all editing in the form that opens you change the code to this:
DoCmd.OpenForm "MYFORMNAME", , , ,acFormReadOnly


You can let them open queries in read only mode with this code:

DoCmd.OpenQuery "myqueryname", , acReadOnly


I wish you success.
Hunter57
Just huntin' for some data.
http://churchmanagementsoftware.googlepages.com

:

I have a db that designed I actively work in. I created the table and form.
When my staff wants to search for a record, they have the form open, click
the field, do ctrl f to find it. The problem I am having is that they are
not watching what they are doing and type over existing data. I created
another form for "searching". How do I get this form to open in a search
capacity and then bring up the actual record in edit mode? They will search
by ssn, name, acct number or case. Please help. I am a beginner/novice user.
 
G

Guest

I sent you an e-mail

Hunter57 said:
Hi LaRana,

Don't feel bad, I'm confused too!

I. Before I can help you I need to know what it is you are trying to
accomplish. Please select one of the following.

1) I am trying to find an existing account or record.

2) I am trying to find and edit an existing account or record.

3) I am trying to add a new account or record to the database.

4). Other--Please explain.


II. About your question about names. It does not matter much what you name
your forms unless you use a word Reserved by Access for special purposes. It
also helps to leave no spaces in your table, field, form, textbox, and
combobox names. You can name them like this if you want: Loan_Form,
Accounts_Form, New_Accounts, etc.

It is a good idea too use names that descibe the object or its purpose. If
the table is about loans the Loans or tblLoans is a good name. If the
purpose of a form is to add new Accounts the NewAccountsForm or
frmNewAccounts are a couple of examples you can use.


III. Since you do not know how to write code see no alternative that to
write the code for you. In order to do this I will need to know the names of
your tables, fields, textboxes, and comboboxes. If this is against company
policy you can use Aliases and then just replace the aliases with the real
names after I write the code.

Please provide the information in this Format:

Tables: TableName
FieldNames:

FieldName1
FieldName2
FieldName3
etc.

Forms: FormName
ControlName:

TextBoxName1
TextBoxName2
ComboBoxName1
etc.

You can email me at pwood57 at gmail dot com. (I use this format to avoid
spam)
Or you can click on the link below, go to my Contact page and send me your
information.

Regards:
Hunter57
http://churchmanagementsoftware.googlepages.com



LaRana said:
Ok here are the questions:
a) can you explain how to do # 1? I want to be sure it is what you mean.

Can we start all over?: ( assume I have two forms form1 and form2 with no
code at all)
form1:
has one combo box where I would the user to input a loan number. Upon input,
another form (form2) displays 3 data fields.

form 2: 3 fields including loan number and other two.

Would you please explain what code to place on form1 and what properties.
Same for form2. Also, what I should name each form so that the code works
w/out any trouble.

I am sorry... I am a little confused here...


Hunter57 said:
Hi LaRana,

First, Using the # symbol in a field can cause problems. The # symbol is an
Access Reserved Character that lets Access know that you are using a date.
It is used like this: #6/23/2007# This is so that Access can recognize that
as a date and not just a number.

It would be a good idea if you can change Loan# to LoanNo or LoanNumber or
LoanID in your tables and your forms.

Back to why your code does not work:

In your code you have Form1 opening in Data entry mode (that is what the ",
, , , acformAdd" does). All you can do is enter new records.

The problem is your code is also trying to find a record and open to it:
"DoCmd.FindRecord (strCbo)". This is not possible when you open the form in
Data Entry Mode using ", , , , acFormAdd".

If you remove the ", , , , acFormAdd" you should be able to go to the record
you desire if it exists. Your OpenToMyRecord combo box must be unbound for
that.

If you remove the "DoCmd.FindRecord (strCbo)" you can add new records to
your database. But your Loan# will not automatically be added.

________________________
If you are trying to add a New Loan Number to your Database automatically I
recommend using the "not in list" event of your combo box.

First, delete the ", , , , acFormAdd" part of your code. This way if the
loan number already exists you can open your form to that loan.

On Form 2 where your OpenToMyRecord combo box is with the new loan number:

1) Make sure that Loan# (and not some other field) is the bound column in
your combo Box query. (if you are not sure how to do this, just let us know
and we can help.)

2) On the Properties sheet of the combo box select the Data tab and change
the "Limit to List" property to Yes.

3) Place this code in the NotInList event of your OpenToMyRecord Combo Box
in Form2 (Change YOURTABLENAME to the name of your table):


Private Sub cboOpenToMyRecord_NotInList(NewData As String, Response As
Integer)

Dim Result
Dim Msg As String
Dim CR As String

CR = Chr$(13)

' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

Select Case MsgBox(" '" & NewData & "' is not in the list." _
& vbCrLf & "" _
& vbCrLf & "Do you want to add '" & NewData & "' to the list?" _
, vbYesNoCancel Or vbQuestion Or vbSystemModal Or _
vbDefaultButton1, " Add Entry To List?")

Case vbYes

' If the user chose Yes, start Form1 in data entry
' mode as a dialog form, passing the new Loan# in
' NewData to the OpenForm method's OpenArgs argument.

DoCmd.OpenForm "Form1", , , , acAdd, acDialog, _
NewData & Me.cboOpenToMyRecord


' Look for the Loan# the user created in Form1.
Result = DLookup("[Loan#]", "YOURTABLENAME", _
"[Loan#] = '" & NewData & "'")
If IsNull(Result) Then
' If the Loan# was not created, set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again!"
Else
' If the Loan# was created, set the Response argument to
' indicate that new data is being added.
Response = acDataErrAdded
End If

'Return to the list
Case vbNo
' If the user selected no set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue

Case vbCancel
' If the user selected no set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
'Delete the entry in the ComboBox
Me!cboOpenToMyRecord = Null

End Select

End Sub

4) ADD THIS CODE TO FORM1:
Private Sub Form_Open(Cancel As Integer)
If Len(Me.OpenArgs) > 0 Then
DoCmd.GoToRecord acForm, "Form1", acNewRec
Me![Loan#] = Me.OpenArgs
Else: DoCmd.GoToRecord acForm, "Form1", acNewRec
End If

End Sub


For more information and different ways of using this event you can do a
google search and find many tutorials and code samples on how to do that.
There are a number of different varieties of the "not in list" event examples
so I suggest you search until you find one that will do what you want and
that you are able to use. Some of them require a lot of coding and others
not so much.


Hope it helps,

Hunter57
http://churchmanagementsoftware.googlepages.com



:

Hi Jana,
I created form1 and form2. Where the records source for form1 is my table
(all data). form2 I am using to ask the user for a loan #. When I open form2
(in form view) I am unable to input a loan number in the "enter loan no"
combo box I created.

I named my Unbound combo box cboOpenToMyRecord_AfterUpdate
Control source is blank
row source is table/query
After update = cboOpenToMyRecord_AfterUpdate()


What am I doing wrong? Here is my code

Option Compare Database
Option Explicit


Private Sub cboOpenToMyRecord_AfterUpdate()
Dim strCbo As Long
strCbo = Me!cboOpenToMyRecord_AfterUpdate

DoCmd.OpenForm "form1", , , , acFormAdd
Forms!form1![loan#].SetFocus
DoCmd.FindRecord (strCbo)
End Sub


:

Hunter57:

I do not know how to write code. I dont guess I know how the combo boxes
work. I have tried changing the properties, however, when I changed it, it
would not let me add a record in add mode. Your suggestions are appreciated.
--
Jana


:

Hi Jana,

You may already know this. If you want to disable editing of an individual
text box or form control, click on the control, open the properties sheet,
click on the Data tab, and changed Locked from No to Yes. They can see the
information but they cannot edit its contents.

I would use unbound combo boxes for them to search with. Here is some code
that I use with a combo box on one form to open other forms to the record I
want.

I am capitalizing parts of the code that you will need to edit.

Private Sub cboOpenToMyRecord_AfterUpdate()
Dim strCbo As Long
strCbo = Me!CBOOPENTOMYRECORD

DoCmd.OpenForm "MYFORMNAME"
Forms!MYFORMNAME![MYPRIMARYKEYFIELDFORMCONTROLNAME].SetFocus
DoCmd.FindRecord (strCbo)
End Sub

MYPRIMARYKEYFIELDFORMCONTROLNAME is the name of the text box or combo box
which shows your table's Primary Key field. It would be something like
CustomerID, txtEmployeeID, cboWorkOrderID, etc.

To allow them to enter new records only you change the code to this:
DoCmd.OpenForm "MYFORMNAME", , , ,acFormAdd

To disable all editing in the form that opens you change the code to this:
DoCmd.OpenForm "MYFORMNAME", , , ,acFormReadOnly


You can let them open queries in read only mode with this code:

DoCmd.OpenQuery "myqueryname", , acReadOnly


I wish you success.
Hunter57
 
G

Guest

Hi LaRana,

I am sorry but I have not received your email. You can try this: Send it to
(Remove the X's) (e-mail address removed)

Regards,
Hunter57
 
G

Guest

I resent it.

Hunter57 said:
Hi LaRana,

I am sorry but I have not received your email. You can try this: Send it to
(Remove the X's) (e-mail address removed)

Regards,
Hunter57
 

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