J
John
I recently asked a question about calling a function,
which was answered, but in turn was told my code
was "convoluted." Perhaps the reader of the code did not
understand it's purpose, but I was wondering if you could
take a look and tell me if it looks good.
The code is in an afterupdate event on an unbound text
box. It's purpose is to either
a) move the form to the record specified in the text box
b) open a separate search form if an "s" is entered
c) open a custom error dialog if the client does not exist
d) display a message box if the search could not run
Here it is, with the new bit:
Private Sub txtClient_AfterUpdate()
On Error GoTo err_clientUpdate '<-- No records or
'invalid use of null
If txtClient = "s" Then
'The OpenSearchForm function opens and binds an
'unbound form for searching for a specific record.
Call OpenSearchForm("Client")
Exit Sub
End If
'I use the following to search
DoCmd.GoToControl "txtClientID" '<--- Bound Field
DoCmd.FindRecord [txtClient]
DoCmd.GoToControl "txtClientID"
If txtClientID <> txtClient Then '<--- If search fails.
'dlgError is an always-open form which is used
'for error display. Note: Not actual errors,
'but errors as the user percieves them.
Forms!dlgerror.Caption = "Invalid Client Number"
Forms!dlgerror!txtTitle = "Invalid Client Number"
Forms!dlgerror!txtError = "The client number you
_entered does not exist. If you wish to add a
_new client, simply click the 'New'button. You
_can either click the 'Search' button or type
_an 's' into the clientID field to search for a
_specific client."
Forms!dlgerror.Visible = True
End If
exit_ClientUpdate:
Exit Sub
err_clientUpdate:
MsgBox "You have no clients currently entered into
_the system, or you did not enter anything
_into the Go To field.", , "Error!"
Exit Sub
End Sub
which was answered, but in turn was told my code
was "convoluted." Perhaps the reader of the code did not
understand it's purpose, but I was wondering if you could
take a look and tell me if it looks good.
The code is in an afterupdate event on an unbound text
box. It's purpose is to either
a) move the form to the record specified in the text box
b) open a separate search form if an "s" is entered
c) open a custom error dialog if the client does not exist
d) display a message box if the search could not run
Here it is, with the new bit:
Private Sub txtClient_AfterUpdate()
On Error GoTo err_clientUpdate '<-- No records or
'invalid use of null
If txtClient = "s" Then
'The OpenSearchForm function opens and binds an
'unbound form for searching for a specific record.
Call OpenSearchForm("Client")
Exit Sub
End If
'I use the following to search
DoCmd.GoToControl "txtClientID" '<--- Bound Field
DoCmd.FindRecord [txtClient]
DoCmd.GoToControl "txtClientID"
If txtClientID <> txtClient Then '<--- If search fails.
'dlgError is an always-open form which is used
'for error display. Note: Not actual errors,
'but errors as the user percieves them.
Forms!dlgerror.Caption = "Invalid Client Number"
Forms!dlgerror!txtTitle = "Invalid Client Number"
Forms!dlgerror!txtError = "The client number you
_entered does not exist. If you wish to add a
_new client, simply click the 'New'button. You
_can either click the 'Search' button or type
_an 's' into the clientID field to search for a
_specific client."
Forms!dlgerror.Visible = True
End If
exit_ClientUpdate:
Exit Sub
err_clientUpdate:
MsgBox "You have no clients currently entered into
_the system, or you did not enter anything
_into the Go To field.", , "Error!"
Exit Sub
End Sub