Form find button

  • Thread starter Thread starter Maggie
  • Start date Start date
M

Maggie

I have a form that opens when the database opens. The
user must type in their HRID into an unbound field and
then click a button to look up their records.

This works great as long as there is a match on the
subform. It pulls up the correct records but when there
isn't a match it starts a new set of records. If the HRID
doesn't match any records on the underlying subform I want
it to come back with an error message and not allow input.

Here is the code on the on click event procedure

Private Sub HRIDCMDBUTTON_Click()
On Error GoTo Err_HRIDCMDBUTTON_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "sample"

stLinkCriteria = "[HRID]=" & "'" & Me![HRID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_HRIDCMDBUTTON_Click:
Exit Sub

Err_HRIDCMDBUTTON_Click:
MsgBox Err.Description
Resume Exit_HRIDCMDBUTTON_Click

End Sub


also - how do I make my initial form maximize so that a
user must input a valid HRID inorder to get to the subform.

Thanks in advance for any help!!

Maggie
 
Maggie,

You can use RecordsetClone.RecordCount when testing whether a form has
records to show. Just put the following in the Open event of the Form that
you want to open after entry of the HRID:

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no records for this HRID."
Cancel = True
End If


hth,
 
It worked! Thanks! Do you know how to maximize the first
form upon open so that the user must input HRID. My form
opens when the database opens but it will not maximize so
that no other part of the database can be accessed.

Thanks again.

Maggie
-----Original Message-----
Maggie,

You can use RecordsetClone.RecordCount when testing whether a form has
records to show. Just put the following in the Open event of the Form that
you want to open after entry of the HRID:

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no records for this HRID."
Cancel = True
End If


hth,
--

Cheryl Fischer, MVP Microsoft Access



I have a form that opens when the database opens. The
user must type in their HRID into an unbound field and
then click a button to look up their records.

This works great as long as there is a match on the
subform. It pulls up the correct records but when there
isn't a match it starts a new set of records. If the HRID
doesn't match any records on the underlying subform I want
it to come back with an error message and not allow input.

Here is the code on the on click event procedure

Private Sub HRIDCMDBUTTON_Click()
On Error GoTo Err_HRIDCMDBUTTON_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "sample"

stLinkCriteria = "[HRID]=" & "'" & Me![HRID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_HRIDCMDBUTTON_Click:
Exit Sub

Err_HRIDCMDBUTTON_Click:
MsgBox Err.Description
Resume Exit_HRIDCMDBUTTON_Click

End Sub


also - how do I make my initial form maximize so that a
user must input a valid HRID inorder to get to the subform.

Thanks in advance for any help!!

Maggie


.
 
DoCmd.Maximize in the open event of your form will cause it to maximize.

You can also set the startup options of the database to hide the database
window - use Tools|Startup. Also, you might want to look in VBA Help to
check out the Modal, PopUp, and BorderStyle properties of forms.

--

Cheryl Fischer, MVP Microsoft Access



It worked! Thanks! Do you know how to maximize the first
form upon open so that the user must input HRID. My form
opens when the database opens but it will not maximize so
that no other part of the database can be accessed.

Thanks again.

Maggie
-----Original Message-----
Maggie,

You can use RecordsetClone.RecordCount when testing whether a form has
records to show. Just put the following in the Open event of the Form that
you want to open after entry of the HRID:

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no records for this HRID."
Cancel = True
End If


hth,
--

Cheryl Fischer, MVP Microsoft Access



I have a form that opens when the database opens. The
user must type in their HRID into an unbound field and
then click a button to look up their records.

This works great as long as there is a match on the
subform. It pulls up the correct records but when there
isn't a match it starts a new set of records. If the HRID
doesn't match any records on the underlying subform I want
it to come back with an error message and not allow input.

Here is the code on the on click event procedure

Private Sub HRIDCMDBUTTON_Click()
On Error GoTo Err_HRIDCMDBUTTON_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "sample"

stLinkCriteria = "[HRID]=" & "'" & Me![HRID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_HRIDCMDBUTTON_Click:
Exit Sub

Err_HRIDCMDBUTTON_Click:
MsgBox Err.Description
Resume Exit_HRIDCMDBUTTON_Click

End Sub


also - how do I make my initial form maximize so that a
user must input a valid HRID inorder to get to the subform.

Thanks in advance for any help!!

Maggie


.
 
Excellent - it worked. I knew about everything but
DoCmd.Maximize.

I am just learning about Visual Basic - unfortunately on a
deadline for this project.

Thanks-

Maggie
-----Original Message-----
DoCmd.Maximize in the open event of your form will cause it to maximize.

You can also set the startup options of the database to hide the database
window - use Tools|Startup. Also, you might want to look in VBA Help to
check out the Modal, PopUp, and BorderStyle properties of forms.

--

Cheryl Fischer, MVP Microsoft Access



It worked! Thanks! Do you know how to maximize the first
form upon open so that the user must input HRID. My form
opens when the database opens but it will not maximize so
that no other part of the database can be accessed.

Thanks again.

Maggie
-----Original Message-----
Maggie,

You can use RecordsetClone.RecordCount when testing whether a form has
records to show. Just put the following in the Open event of the Form that
you want to open after entry of the HRID:

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no records for this HRID."
Cancel = True
End If


hth,
--

Cheryl Fischer, MVP Microsoft Access



I have a form that opens when the database opens. The
user must type in their HRID into an unbound field and
then click a button to look up their records.

This works great as long as there is a match on the
subform. It pulls up the correct records but when there
isn't a match it starts a new set of records. If the HRID
doesn't match any records on the underlying subform I want
it to come back with an error message and not allow input.

Here is the code on the on click event procedure

Private Sub HRIDCMDBUTTON_Click()
On Error GoTo Err_HRIDCMDBUTTON_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "sample"

stLinkCriteria = "[HRID]=" & "'" & Me![HRID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_HRIDCMDBUTTON_Click:
Exit Sub

Err_HRIDCMDBUTTON_Click:
MsgBox Err.Description
Resume Exit_HRIDCMDBUTTON_Click

End Sub


also - how do I make my initial form maximize so that a
user must input a valid HRID inorder to get to the subform.

Thanks in advance for any help!!

Maggie


.


.
 
Glad to hear this worked for you; thanks for letting us know.

--

Cheryl Fischer, MVP Microsoft Access



Maggie said:
Excellent - it worked. I knew about everything but
DoCmd.Maximize.

I am just learning about Visual Basic - unfortunately on a
deadline for this project.

Thanks-

Maggie
-----Original Message-----
DoCmd.Maximize in the open event of your form will cause it to maximize.

You can also set the startup options of the database to hide the database
window - use Tools|Startup. Also, you might want to look in VBA Help to
check out the Modal, PopUp, and BorderStyle properties of forms.

--

Cheryl Fischer, MVP Microsoft Access



It worked! Thanks! Do you know how to maximize the first
form upon open so that the user must input HRID. My form
opens when the database opens but it will not maximize so
that no other part of the database can be accessed.

Thanks again.

Maggie
-----Original Message-----
Maggie,

You can use RecordsetClone.RecordCount when testing
whether a form has
records to show. Just put the following in the Open
event of the Form that
you want to open after entry of the HRID:

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no records for this HRID."
Cancel = True
End If


hth,
--

Cheryl Fischer, MVP Microsoft Access



message
I have a form that opens when the database opens. The
user must type in their HRID into an unbound field and
then click a button to look up their records.

This works great as long as there is a match on the
subform. It pulls up the correct records but when there
isn't a match it starts a new set of records. If the
HRID
doesn't match any records on the underlying subform I
want
it to come back with an error message and not allow
input.

Here is the code on the on click event procedure

Private Sub HRIDCMDBUTTON_Click()
On Error GoTo Err_HRIDCMDBUTTON_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "sample"

stLinkCriteria = "[HRID]=" & "'" & Me![HRID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_HRIDCMDBUTTON_Click:
Exit Sub

Err_HRIDCMDBUTTON_Click:
MsgBox Err.Description
Resume Exit_HRIDCMDBUTTON_Click

End Sub


also - how do I make my initial form maximize so that a
user must input a valid HRID inorder to get to the
subform.

Thanks in advance for any help!!

Maggie


.


.
 
Back
Top