If no fill then msgbox... (1 Viewer)

Onlylonely

Registered User.
Local time
Today, 19:22
Hi Guys,

Appreciate if you could help me out.

Objective: My forms have lot of radio button and i want it to come out msgbox if the user not selected the radio button.

Issue i'm facing: i try to tag all the radio button with STEP1. then use tag to control them. Below is my code. NA = 3

But i cant achieve what i want.

Code:
Function checkforSTEP1() As Boolean

checkforSTEP1 = True

Dim ctrl As Control

For Each ctrl In Me.Controls
If ctrl.Tag = "STEP1" Then
[COLOR="Red"]If .Value(ctrl) = 3 Then[/COLOR] [COLOR="red"]<< Error showing here[/COLOR]
checkforSTEP1 = False
End If

End If

Next

End Function

If checkforSTEP1() = False Then

    MsgBox ("Error : All fields are mandatory !!")
    
Else

End If
 

isladogs

MVP / VIP
Local time
Today, 12:22
Try this


Code:
Function checkforSTEP1() As Boolean

checkforSTEP1 = True

Dim ctrl As Control

For Each ctrl In Me.Controls
If .Tag = "STEP1" And .Value= 3 Then
  checkforSTEP1 = False
  MsgBox "Error : All fields are mandatory !!"   
End If

End Function

It may be necessary to limit to certain types of control only e.g. acTextbox as not all controls can have a value
 

Onlylonely

Registered User.
Local time
Today, 19:22
Try this


Code:
Function checkforSTEP1() As Boolean

checkforSTEP1 = True

Dim ctrl As Control

For Each ctrl In Me.Controls
If .Tag = "STEP1" And .Value= 3 Then
  checkforSTEP1 = False
  MsgBox "Error : All fields are mandatory !!"   
End If

End Function

It may be necessary to limit to certain types of control only e.g. acTextbox as not all controls can have a value


There is an error on the code. Refer to attachment.
 

Attachments

  • invalid.JPG
    invalid.JPG
    37.5 KB · Views: 57

pbaldy

Wino Moderator
Staff member
Local time
Today, 04:22
The posted code assumes a With block has been established. Use

ctrl.Tag
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 04:22
You have controls that don't have a Value property. Either limit your test to appropriate control types first or have a second If block testing for the value inside the test for the tag.
 

isladogs

MVP / VIP
Local time
Today, 12:22
Hopefully correct this time.
It works but the message seems inappropriate.
If the value of the control is 3 then it has been completed so as an end user I would be confused.

Code:
Function checkforstep1() As Boolean

checkforstep1 = True

Dim ctrl As Control

For Each ctrl In Me.Controls
Select Case ctrl.ControlType

Case acTextBox, acComboBox
If ctrl.Tag = "step1" And ctrl.Value = 3 Then
  checkforstep1 = False
  MsgBox "error : all fields are mandatory !!"
End If

Case Else
'do nothing - this is just for info and could be omitted

End Select

Next

End Function

Could you instead check whether any of these controls are empty
 

Users who are viewing this thread

Top Bottom