Checkbox in Option Group

sub_nitrox

Registered User.
Local time
Today, 10:27
Joined
Sep 28, 2006
Messages
20
Hi,
I need an help on my DB.
I have a form with some comboboxes and checkboxes inside an option group, which is a value of a table.
The table is named TB_ALLEGATI and the field inside this table is named TIPO_CANALE (this also the option group name).

the checkbox inside the option group are named SMS, MMS and VOICE with value as 1, 2 and 3.

I want to save the value checked by the user and store it in the table TB_ALLEGATI, but the problem is that i'm able to save only 1,2 or 3 and not the value name that are SMS, MMS and VOICE.

Have you a suggestion on how to perform this action?
Have you any code example?

Thanks in advance.
Regards.
Antonio.
 
The first thing I would do is unbind the option group to your field. Then I would add a textbox bound to your field, and set the visible property to no.

In the AfterUpdate event of the option group, use a Case statement to update your bound textbox.

In the current event of your form, set your option group to whatever is in the textbox.

Make sense?
 
Hi,
i found right now the solution with a Case statement to transcode the number value (1,2 and 3) to text and I'm also able to save it in the table.

THE ONLY BIG PROBLEM now is that i'm not abel to see the checkbox selected in the form and I don't know why?

The code i putted in the After Update event is this:
----------------
Private Sub TIPO_CANALE_AfterUpdate()
'Me.TIPO_CANALE = strField
Dim strCondition As String
Select Case TIPO_CANALE
Case 1
strCondition = "SMS"
Case 2
strCondition = "MMS"
Case 3
strCondition = "VOCE"
Case 4
strCondition = "VIDEO"
Case 5
strCondition = "WAP"
Case Else
strCondition = "UNKNOWN"
End Select
Me.TIPO_CANALE = strCondition
End Sub

It works well but, again, I'm not able to see the checkbox that I select, despite the text value ir correctly saved in the table after the save command.

ANY SUGGESTION ????
thanks,
Antonio
 
You need to synch up your text box and your option group using the "On Current" event of the for.

Basically, you'll want to use a case statment and look at the value of your textbox, and then set your option group accordingly.
 
Sorry,
but what do you mean?
I don't have a text box.
I only have an Option Group named TIPO_CANALE with inside 5 checkbox named SMS, MMS and so on ....

I'm right now able to save the value that I select fomr the checkbox, but the problem is that on the screen I'm not able to see the checkbox updated according to the selection.

Seem to be a problem related to the Option Group Refresh, but i tried also the Requery function on the Option Group.

Any idea?
 
Your names are confusing, so I'm going to assume that the field you are trying to update is called TIPO_CANALE, and the option group you've created is called fraTIP_CANALE.

Add a textbox bound to TIPO_CANALE. If you want, you can hide this textbox. Call it txtTIPO_CANALE. On the Current Event of your form, you can use the following code:

Select Case me.txtTIPO_CANALE
Case "SMS"
me.fraTIPO_CANALE = 1
Case "MMA"
me.fraTIPO_CANALE = 2
Case "VOCE"
me.fraTIPO_CANALE = 3
Case "VIDEO"
me.fraTIPO_CANALE = 4
Case "WAP"
me.fraTIPO_CANALE = 5
End Select
 
Hi, thanks for your feedback.

I don't understand why I have tro create a textbox.
I'm able to perform what I want like save the value in my fiedl table after I check the checkbox and so on.
The only problem maybe is in the ase statement, where after I select the checkbox preferred, I cannot see the black tie inside the checkbox, but at the same time the value related to that check box is correctly saved.

Can we find a solution on why I'm not able to see the black tie inside the checkbox?

Thanks,
Antonio.
 
If you want, post the db and I'll take a look.
 
Hi,
thank you for yuor support. Please find attached a part of the DB I realized.
In the frm_TERMINAL_ADD, you'll find the TIPO CANALE Option group with different checkbox.
If you try to compile the form and try to select a checkbox, you are not able to see the checkbox selected but the value is correctly saved in the table (TB_ALLEGATI2 in the TIPO_CANALE field.)

I'm waiting for your suggestion.
Regards,
Antonio.
 

Attachments

Any reason you are using an unbound form?? Any reason that you have two save routines that do the same thing??

Anyway, I fixed it. Since your form is unbound, you want to calculate the value of your option group when you save the record, not after you update the group. See attached...
 

Attachments

Hi ejstefl,
thanks for your support. It works perfectly!!!!! Wonderful.

Have you also an idea on what code to put in the save function to check if some field have been filled in?

I'd like to make a check of some fields in the form, to verify if they have a value, before to click the save button?
Any idea?

Thanks again and have a great day!!!!
Cheers,
Antonio.
 
All you have to do is test the controls to see if they have a value. If they do not, then don't write the record to your database!

Again, though, I must ask why you have two save routines that run (that appear to be pretty similar) and why you are using an unbound form??
 
Hi,
do you mean the two saving funciotn named save_termin_info_curr and save_termin_info_store?
If yes, is only to have an history of all actions performed to the data, infact the second funcion store all data in a different table named TB_STOR_ALLEGATI2 that I haven't attached as example.
This ios my reason.
About why I'm using an unbound form, this is for me an hard question. I have inherited this DB form a colleague so ....

CAn you post to me some code example on how make a control on the fields before the save?
I added some if but they don't work.

Thanks for your help, again.
A.
 
If isnull(me.txtField) Then
msgbox "You must complete Field 1.",vbokonly+vbinformation, "Missing Field 1"
exit sub
End If

Do that for each field you want to check. If you want to be nice to your users, you could code it to check each box before exiting the sub and display one error message with all the missing fields.
 
Hi,
I tried to put this code in the Before Update event of the form but maybe there is something of wrong or what else ....
Here the code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Trim(Me.cboNOME_PROVIDER & "") = "" Then
MsgBox "Please enter a Nome Provider"
Me.cboNOME_PROVIDER.SetFocus
ElseIf Trim(Me.NUM_BREVE & "") = "" Then
MsgBox "Please enter a Numero Breve"
Me.NUM_BREVE.SetFocus
ElseIf Trim(Me.NUM_MAM1 & "") = "" Then
MsgBox "Please enter a Numero MAM"
Me.NUM_MAM1.SetFocus
ElseIf Trim(Me.TIPO_CANALE & "") = "" Then
MsgBox "Please Ensure you have Selected the TIPO CANALE"
Me.TIPO_CANALE.SetFocus
Else
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close
End If
End Sub


Do you think this could do that I want or what?
I have to put it in the SAve function?

Thanks,
Antonio.
 
You are using an unbound form. Therefore, there is no before update event!!

You need to put it on your save button.
 
Sorry for my ignorance,
but I tried just a statement and i got an error in compile on the "End Sub".

I know that I have a funciotn, but I'm not able to stop the saving after the pop up come up saying please fill the NuMMAM etc....
Colud you give me a solution on this part of code?
Thanks for your patient!!

Here the code:

Private Function save_terminal_info_curr() As Long
Dim db As Database
Dim rs As Recordset
Dim ssql, aa
Dim strCondition As String
Set db = CurrentDb
ssql = "TB_ALLEGATI2"
Set rs = db.OpenRecordset(ssql, dbOpenDynaset)
rs.AddNew

Select Case Me.TIPO_CANALE
Case 1
strCondition = "SMS"
Case 2
strCondition = "MMS"
Case 3
strCondition = "VOCE"
Case 4
strCondition = "VIDEO"
Case 5
strCondition = "WAP"
Case Else
strCondition = "UNKNOWN"
End Select


rs!NOME_PROVIDER = Me.cboNOME_PROVIDER
rs!NOME_SERVIZIO_COMMERCIALE = Me.NOME_SERVIZIO_COMMERCIALE
rs!NUM_BREVE = Me.NUM_BREVE
rs!NUM_MAM1 = Me.NUM_MAM1
'rs!NUM_MAM2 = Me.NUM_MAM2
rs!DESCRIZIONE_SERVIZIO = Me.DESCRIZIONE_SERVIZIO
rs!CLASSE_COSTO_SMS = Me.CLASSE_COSTO_SMS
rs!CLASSE_COSTO_MMS = Me.CLASSE_COSTO_MMS
rs!CONTENT_SMS = Me.CONTENT_SMS
rs!CONTENT_MMS = Me.CONTENT_MMS
rs!NUM_CC = Me.NUM_CC
rs!SUPPORT_TIME = Me.SUPPORT_TIME
rs!TIPO_SERVIZIO = Me.TIPO_SERVIZIO
rs!SINTAX_ATTIV = Me.SINTAX_ATTIV
rs!SINTAX_DISAT = Me.SINTAX_DISAT
rs!TIPO_CANALE = strCondition
'rs!NUM_MAMMT_USCITA = Me.NUM_MAMMT_USCITA
rs!DATA_INS = Now()
aa = rs!ID_ALL

'*********************************************************
If IsNull(Me.NUM_MAM1) Then
MsgBox "You must complete Num Mam.", vbOKOnly + vbInformation, "Missing Nun Mam"
End Sub
End If

rs.Update
rs.Close

save_terminal_info_curr = aa
End Function
 
You're checking to see if the box is filled in while its already too late!! Do you understand what the code is doing? All those lines that start with rs! are actually writing the record to your table. By the time you're checking to see if a field is null, you've already written the record!! Plus, you're using End Sub in a function.

Place the code at the begining, right after all of your variable declarations, and change it to read:

If IsNull(Me.NUM_MAM1) Then
MsgBox "You must complete Num Mam.", vbOKOnly + vbInformation, "Missing Nun Mam"
Exit Function
End If
 
Hi, Thanks for your support.

Also with your suggestion I have a problem and in partcular, after I receive on screen the pop up that advertise the missing field, the user is not able to enter the missing data, because an ID to the records is assigned.

Therefore, the users have to close the form and open it again. That is not that I want. I'd like to come back to the current form and insert the missing data.

Have you any idea?
Right now I modified the code to this:

Private Function save_terminal_info_curr() As Long
Dim db As Database
Dim rs As Recordset
Dim ssql, aa
Dim strCondition As String

If IsNull(Me.cboNOME_PROVIDER) Then
MsgBox "You must complete Nome Provider.", vbOKOnly + vbInformation, "Missing Nome Provider"
Exit Function
End If


If IsNull(Me.NUM_MAM1) Then
MsgBox "You must complete Numero MAM.", vbOKOnly + vbInformation, "Missing Numero MAM"
Exit Function
End If

If IsNull(Me.NUM_BREVE) Then
MsgBox "You must complete Numero Breve.", vbOKOnly + vbInformation, "Missing Numero Breve"
Exit Function
End If

If IsNull(Me.TIPO_CANALE) Then
MsgBox "You must complete Tipo Canale.", vbOKOnly + vbInformation, "Missing Tipo Canale"
Exit Function
End If

Set db = CurrentDb
ssql = "TB_ALLEGATI2"
Set rs = db.OpenRecordset(ssql, dbOpenDynaset)
rs.AddNew

Select Case Me.TIPO_CANALE
Case 1
strCondition = "SMS"
Case 2
strCondition = "MMS"
Case 3
strCondition = "VOCE"
Case 4
strCondition = "VIDEO"
Case 5
strCondition = "WAP"
Case Else
strCondition = "UNKNOWN"
End Select

rs!NOME_PROVIDER = Me.cboNOME_PROVIDER
rs!NOME_SERVIZIO_COMMERCIALE = Me.NOME_SERVIZIO_COMMERCIALE
rs!NUM_BREVE = Me.NUM_BREVE
rs!NUM_MAM1 = Me.NUM_MAM1
'rs!NUM_MAM2 = Me.NUM_MAM2
rs!DESCRIZIONE_SERVIZIO = Me.DESCRIZIONE_SERVIZIO
rs!CLASSE_COSTO_SMS = Me.CLASSE_COSTO_SMS
rs!CLASSE_COSTO_MMS = Me.CLASSE_COSTO_MMS
rs!CONTENT_SMS = Me.CONTENT_SMS
rs!CONTENT_MMS = Me.CONTENT_MMS
rs!NUM_CC = Me.NUM_CC
rs!SUPPORT_TIME = Me.SUPPORT_TIME
rs!TIPO_SERVIZIO = Me.TIPO_SERVIZIO
rs!SINTAX_ATTIV = Me.SINTAX_ATTIV
rs!SINTAX_DISAT = Me.SINTAX_DISAT
rs!TIPO_CANALE = strCondition
'rs!NUM_MAMMT_USCITA = Me.NUM_MAMMT_USCITA
rs!DATA_INS = Now()
aa = rs!ID_ALL

rs.Update
rs.Close

save_terminal_info_curr = aa
End Function

Thanks Again for your support.:)
 

Users who are viewing this thread

Back
Top Bottom