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 |
#11
|
|||
|
|||
Stop incomplete details by the user?
Hi I am trying your piece of code on the BeforeUpdate and I get a complie
error at .SetFocus can you help me out here please? Jo "BruceM via AccessMonster.com" wrote: 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 . |
#12
|
|||
|
|||
Stop incomplete details by the user?
Hi John sorry to be a pain but I keep looking to see where I'm going wrong
but I dont no. I have put the following code in the class module section: Option Compare Database Function CheckFields() If Nz(Forms![Data Entry]![Inspection By], "") "" And Nz(Forms![Data Entry]![Channel], "") "" And _ Nz(Forms![Data Entry]![Station], "") "" Then [Command148].Enabled = True Else [Command148].Enabled = False End If End Function and then I have put the following code on the AfterUpdate: Private Sub Form_AfterUpdate() Call CheckFields End Sub I think I may be calling the function wrong? "John Spencer" wrote: 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 . . |
#13
|
|||
|
|||
Stop incomplete details by the user?
You have to fully qualify the command button as well
Forms![Data Entry]![Command148].Enabled = True ..... Forms![Data Entry]![Command148].Enabled = False "jo" wrote: Hi John sorry to be a pain but I keep looking to see where I'm going wrong but I dont no. I have put the following code in the class module section: Option Compare Database Function CheckFields() If Nz(Forms![Data Entry]![Inspection By], "") "" And Nz(Forms![Data Entry]![Channel], "") "" And _ Nz(Forms![Data Entry]![Station], "") "" Then [Command148].Enabled = True Else [Command148].Enabled = False End If End Function and then I have put the following code on the AfterUpdate: Private Sub Form_AfterUpdate() Call CheckFields End Sub I think I may be calling the function wrong? "John Spencer" wrote: 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 . . |
#14
|
|||
|
|||
Stop incomplete details by the user?
Try just
CheckFields without the CALL If you use CALL I think you might have to use Call Checkfields() Note the addition of the parentheses. I could be wrong about that. I've almost never used the Call functionality. John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County jo wrote: Hi John sorry to be a pain but I keep looking to see where I'm going wrong but I dont no. I have put the following code in the class module section: Option Compare Database Function CheckFields() If Nz(Forms![Data Entry]![Inspection By], "") "" And Nz(Forms![Data Entry]![Channel], "") "" And _ Nz(Forms![Data Entry]![Station], "") "" Then [Command148].Enabled = True Else [Command148].Enabled = False End If End Function and then I have put the following code on the AfterUpdate: Private Sub Form_AfterUpdate() Call CheckFields End Sub I think I may be calling the function wrong? "John Spencer" wrote: 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 . . |
#15
|
|||
|
|||
Stop incomplete details by the user?
Hi Bruce I tried your code and get a msg box to say a field is in complete
and when you click ok the form closes? The user is not able to complete the empty field. So I think I need some code to allow the user to complete the fields? Can you help plz: Private Sub Form_AfterUpdate() Dim strTitle As String strTitle = "Incomplete Data" If Nz(Me.[Channel], "") = "" Then MsgBox "Please enter Channel", vbInformation, strTitle Cancel = True Me.[Channel].SetFocus ElseIf Nz(Me.[Inspection By], "") = "" Then MsgBox "Please enter Inspection By", vbInformation, strTitle Cancel = True Me.[Inspection By].SetFocus ElseIf Nz(Me.[Station], "") = "" Then MsgBox "Please enter Station", vbInformation, strTitle Cancel = True Me.[Station].SetFocus End If End Sub "BruceM via AccessMonster.com" wrote: 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 . |
|
Thread Tools | |
Display Modes | |
|
|