If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Stop incomplete details by the user?
Is it possible to add code to a form to inform the user that a field has not
been entered once they click the print button? And what would the code be? please Thanks Jo |
#2
|
|||
|
|||
Stop incomplete details by the user?
Ideally the button should be disabled until all the relevant fields have data
in them but to answer your question In the click event of your button put something like this If Nz(Me.[Your Field Name],"") = "" Then MsgBox "Please enter data into [Your Field Name]", vbInformation + vbOKOnly, "Incomplete Data" Me.[Your Field Name].SetFocus Else ' continue with printing End If "jo" wrote: Is it possible to add code to a form to inform the user that a field has not been entered once they click the print button? And what would the code be? please Thanks Jo |
#3
|
|||
|
|||
Stop incomplete details by the user?
What if there is more that one field they have missed?
these are the usual fields they miss: [Inspection By] [Channel] [Station] thanks jo "RonaldoOneNil" wrote: Ideally the button should be disabled until all the relevant fields have data in them but to answer your question In the click event of your button put something like this If Nz(Me.[Your Field Name],"") = "" Then MsgBox "Please enter data into [Your Field Name]", vbInformation + vbOKOnly, "Incomplete Data" Me.[Your Field Name].SetFocus Else ' continue with printing End If "jo" wrote: Is it possible to add code to a form to inform the user that a field has not been entered once they click the print button? And what would the code be? please Thanks Jo |
#4
|
|||
|
|||
Stop incomplete details by the user?
I would put the following into the print button code:
Me.Dirty = False This attempts to save the record. Then, in the form's Before Update event: Private Sub Form_BeforeUpdate (Cancel as Integer) Dim strTitle as String strTitle = "Incomplete Data" If Nz(Me.[InspectionBy],"") = "" Then MsgBox "Please enter Inspection By data", vbInformation, strTitle Cancel = True Me.[txtInspectionBy].SetFocus ElseIf Nz(Me.[Channel],"") = "" Then MsgBox "Please enter Channel", vbInformation, strTitle Cancel = True Me.txtChannel.SetFocus ElseIf Nz(Me.[Station],"") = "" Then MsgBox "Please enter Station", vbInformation, strTitle Cancel = True Me.txtStation.SetFocus End If Station is the field, and txtStation is the text box bound to Station (to use one example). Use your actual names, of course. Here is a generic routine that Albert Kallal provided. It is well worth taking a few minutes to figure it out. Just use your control names and error messages. For instance, if txtInspectionBy is bound to the InspectionBy field, the first entry in the list below would be: colFields.Add "txtInspectionBy|Inspection By" Albert had used a comma instead of the pipe character (|) in the above and in the Split functions, but I used the pipe character so I can have a comma in the validation text if I want. Albert's code and explanation follow. ******************* I use the following "general" code routine to give custom messages for fields that are not filled out. The code below is a great way to verify fields that you want to be requited. Another nice feature is that after the given message, the cursor (focus) moves to the field in question. The code is used as follows: In the forms before update event..you go: Cancel = MyVerify. And, then the two following routines need be put into the form's module. You can see how in the first example, you just put in the list of controls that you want requited, and also the text "error" message to display. Note carefully how the full string is enclosed in quotes. This routine is called in the forms Load event: Private Function MyVerify() As Boolean Dim colFields As New Collection MyVerify = False colFields.Add "TourDate|Tour date" colFields.Add "Description|Description" colFields.Add "City|City" colFields.Add "cboProvince|Province" colFields.Add "StartDate|Start date" colFields.Add "EndDate|end date" MyVerify = vfields(colFields) End Function Private Function vfields(colFields As Collection) As Boolean Dim strErrorText As String Dim strControl As String Dim i As Integer vfields = False For i = 1 To colFields.Count strControl = Split(colFields(i), "|")(0) strErrorText = Split(colFields(i), "|")(1) If IsNull(Me(strControl)) = True Then MsgBox strErrorText & " is required", vbExclamation, "Required Field" Me(strControl).SetFocus vfields = True Exit Function End If Next i End Function -- Albert D. Kallal (Access MVP) Edmonton, Alberta Canada jo wrote: What if there is more that one field they have missed? these are the usual fields they miss: [Inspection By] [Channel] [Station] thanks jo Ideally the button should be disabled until all the relevant fields have data in them but to answer your question [quoted text clipped - 12 lines] please Thanks Jo -- Message posted via http://www.accessmonster.com |
#5
|
|||
|
|||
Stop incomplete details by the user?
Create a function similar to below and then call it from the after update
event of each of your 3 fields and possibly the On Current event of the form. Function CheckFields() If Nz([Inspection By],"") "" And Nz([Channel],"") "" And Nz([Station],"") "" Then [PrintButtonName].Enabled = True Else [PrintButtonName].Enabled = False End If End Function "jo" wrote: What if there is more that one field they have missed? these are the usual fields they miss: [Inspection By] [Channel] [Station] thanks jo "RonaldoOneNil" wrote: Ideally the button should be disabled until all the relevant fields have data in them but to answer your question In the click event of your button put something like this If Nz(Me.[Your Field Name],"") = "" Then MsgBox "Please enter data into [Your Field Name]", vbInformation + vbOKOnly, "Incomplete Data" Me.[Your Field Name].SetFocus Else ' continue with printing End If "jo" wrote: Is it possible to add code to a form to inform the user that a field has not been entered once they click the print button? And what would the code be? please Thanks Jo |
#6
|
|||
|
|||
Stop incomplete details by the user?
hi i do not know code to well and when I put this piece in it is high lighted
in red so I am assuming there is an error with puchuation? If Nz([Inspection By],"") "" And Nz([Channel],"") "" And Nz([Station],"") "" Then "RonaldoOneNil" wrote: Create a function similar to below and then call it from the after update event of each of your 3 fields and possibly the On Current event of the form. Function CheckFields() If Nz([Inspection By],"") "" And Nz([Channel],"") "" And Nz([Station],"") "" Then [PrintButtonName].Enabled = True Else [PrintButtonName].Enabled = False End If End Function "jo" wrote: What if there is more that one field they have missed? these are the usual fields they miss: [Inspection By] [Channel] [Station] thanks jo "RonaldoOneNil" wrote: Ideally the button should be disabled until all the relevant fields have data in them but to answer your question In the click event of your button put something like this If Nz(Me.[Your Field Name],"") = "" Then MsgBox "Please enter data into [Your Field Name]", vbInformation + vbOKOnly, "Incomplete Data" Me.[Your Field Name].SetFocus Else ' continue with printing End If "jo" wrote: Is it possible to add code to a form to inform the user that a field has not been entered once they click the print button? And what would the code be? please Thanks Jo |
#7
|
|||
|
|||
Stop incomplete details by the user?
Does your code include the line Function CheckFields() as shown?
I would use the Me.prefix, as it saves typing and reduces typos by bringing up a pick list after you type Me., and will help the code run more efficiently for reasons I probably don't need to get into he If Nz(Me.[Inspection By],"") "" etc. Note that the code only enables/disables the command button, but does not explain why it is disabled. If the fields are required, use the form's Before Update event for validation. jo wrote: hi i do not know code to well and when I put this piece in it is high lighted in red so I am assuming there is an error with puchuation? If Nz([Inspection By],"") "" And Nz([Channel],"") "" And Nz([Station],"") "" Then Create a function similar to below and then call it from the after update event of each of your 3 fields and possibly the On Current event of the form. [quoted text clipped - 28 lines] please Thanks Jo -- Message posted via http://www.accessmonster.com |
#8
|
|||
|
|||
Stop incomplete details by the user?
If Nz([Inspection By],"") "" And Nz([Channel],"") "" And
Nz([Station],"") "" Then Should all be on one line. If you copied and pasted from the newsreader it probably got broken into two lines and therefore is wrong. Alternative is to use line continuation characters (space underscore) at the end of the line. Something like: If Nz([Inspection By],"") "" _ And Nz([Channel],"") "" - And Nz([Station],"") "" Then [PrintButtonName].Enabled = True Else [PrintButtonName].Enabled = False End If John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County jo wrote: hi i do not know code to well and when I put this piece in it is high lighted in red so I am assuming there is an error with puchuation? If Nz([Inspection By],"") "" And Nz([Channel],"") "" And Nz([Station],"") "" Then "RonaldoOneNil" wrote: Create a function similar to below and then call it from the after update event of each of your 3 fields and possibly the On Current event of the form. Function CheckFields() If Nz([Inspection By],"") "" And Nz([Channel],"") "" And Nz([Station],"") "" Then [PrintButtonName].Enabled = True Else [PrintButtonName].Enabled = False End If End Function "jo" wrote: What if there is more that one field they have missed? these are the usual fields they miss: [Inspection By] [Channel] [Station] thanks jo "RonaldoOneNil" wrote: Ideally the button should be disabled until all the relevant fields have data in them but to answer your question In the click event of your button put something like this If Nz(Me.[Your Field Name],"") = "" Then MsgBox "Please enter data into [Your Field Name]", vbInformation + vbOKOnly, "Incomplete Data" Me.[Your Field Name].SetFocus Else ' continue with printing End If "jo" wrote: Is it possible to add code to a form to inform the user that a field has not been entered once they click the print button? And what would the code be? please Thanks Jo |
#9
|
|||
|
|||
Stop incomplete details by the user?
Hi guys the underscore solved one problem but now I have a complie error
“External name not defined” I have put this on the form AfterUpdate to call the CheckFields Function: Private Sub Form_AfterUpdate() Call CheckFields End Sub And I have put the code below in the Module and I have not named this its just Module1 and the Complie Error is ([Inspection By],: Option Compare Database Option Explicit Function CheckFields() If Nz([Inspection By], "") "" And Nz([Channel], "") "" And _ Nz([Station/Machine], "") "" Then [Command148_Click].Enabled = True Else [Command148_Click].Enabled = False End If End Function "John Spencer" wrote: If Nz([Inspection By],"") "" And Nz([Channel],"") "" And Nz([Station],"") "" Then Should all be on one line. If you copied and pasted from the newsreader it probably got broken into two lines and therefore is wrong. Alternative is to use line continuation characters (space underscore) at the end of the line. Something like: If Nz([Inspection By],"") "" _ And Nz([Channel],"") "" - And Nz([Station],"") "" Then [PrintButtonName].Enabled = True Else [PrintButtonName].Enabled = False End If John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County jo wrote: hi i do not know code to well and when I put this piece in it is high lighted in red so I am assuming there is an error with puchuation? If Nz([Inspection By],"") "" And Nz([Channel],"") "" And Nz([Station],"") "" Then "RonaldoOneNil" wrote: Create a function similar to below and then call it from the after update event of each of your 3 fields and possibly the On Current event of the form. Function CheckFields() If Nz([Inspection By],"") "" And Nz([Channel],"") "" And Nz([Station],"") "" Then [PrintButtonName].Enabled = True Else [PrintButtonName].Enabled = False End If End Function "jo" wrote: What if there is more that one field they have missed? these are the usual fields they miss: [Inspection By] [Channel] [Station] thanks jo "RonaldoOneNil" wrote: Ideally the button should be disabled until all the relevant fields have data in them but to answer your question In the click event of your button put something like this If Nz(Me.[Your Field Name],"") = "" Then MsgBox "Please enter data into [Your Field Name]", vbInformation + vbOKOnly, "Incomplete Data" Me.[Your Field Name].SetFocus Else ' continue with printing End If "jo" wrote: Is it possible to add code to a form to inform the user that a field has not been entered once they click the print button? And what would the code be? please Thanks Jo . |
#10
|
|||
|
|||
Stop incomplete details by the user?
You cannot refer to fields or controls on a form in a general module in that way. You would need to fully qualify the control names Forms![Name of Form]![Name of Control] If Nz([Inspection By], "") ... becomes If Nz(Forms![Name of Form]![Inspection By], "") ... That function code should be in the VBA class module for the form and not in a general VBA module. Once that function is available you should be calling it from several places. The form's Current event so the button Command148 (not command148_Click) would be enabled or disabled when you open the form or switch records on the form. Also call it from the afterupdate event of all three controls so the button would be enabled/disabled as appropriate as you entered/modified data. John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County jo wrote: Hi guys the underscore solved one problem but now I have a complie error “External name not defined” I have put this on the form AfterUpdate to call the CheckFields Function: Private Sub Form_AfterUpdate() Call CheckFields End Sub And I have put the code below in the Module and I have not named this its just Module1 and the Complie Error is ([Inspection By],: Option Compare Database Option Explicit Function CheckFields() If Nz([Inspection By], "") "" And Nz([Channel], "") "" And _ Nz([Station/Machine], "") "" Then [Command148_Click].Enabled = True Else [Command148_Click].Enabled = False End If End Function "John Spencer" wrote: If Nz([Inspection By],"") "" And Nz([Channel],"") "" And Nz([Station],"") "" Then Should all be on one line. If you copied and pasted from the newsreader it probably got broken into two lines and therefore is wrong. Alternative is to use line continuation characters (space underscore) at the end of the line. Something like: If Nz([Inspection By],"") "" _ And Nz([Channel],"") "" - And Nz([Station],"") "" Then [PrintButtonName].Enabled = True Else [PrintButtonName].Enabled = False End If John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County jo wrote: hi i do not know code to well and when I put this piece in it is high lighted in red so I am assuming there is an error with puchuation? If Nz([Inspection By],"") "" And Nz([Channel],"") "" And Nz([Station],"") "" Then "RonaldoOneNil" wrote: Create a function similar to below and then call it from the after update event of each of your 3 fields and possibly the On Current event of the form. Function CheckFields() If Nz([Inspection By],"") "" And Nz([Channel],"") "" And Nz([Station],"") "" Then [PrintButtonName].Enabled = True Else [PrintButtonName].Enabled = False End If End Function "jo" wrote: What if there is more that one field they have missed? these are the usual fields they miss: [Inspection By] [Channel] [Station] thanks jo "RonaldoOneNil" wrote: Ideally the button should be disabled until all the relevant fields have data in them but to answer your question In the click event of your button put something like this If Nz(Me.[Your Field Name],"") = "" Then MsgBox "Please enter data into [Your Field Name]", vbInformation + vbOKOnly, "Incomplete Data" Me.[Your Field Name].SetFocus Else ' continue with printing End If "jo" wrote: Is it possible to add code to a form to inform the user that a field has not been entered once they click the print button? And what would the code be? please Thanks Jo . |
|
Thread Tools | |
Display Modes | |
|
|