Condividi tramite

Collegare Option Button con TextBox [Access/VBA]

Anonimo
2013-01-24T11:10:25+00:00

Salve volevo sapere se è possibile legare un Option Button con una text box.

In pratica quello che vorrei è la seguente cosa:

se flaggo su un opzione si deve abilitare un text specifica textbox.

Su un comando ho poi una condizione di apertura di un form del tipo:

(questa vale solo se ho una specifica text box ID Buyer):

Private Sub Visualizza_Buyer_Click()

If Nz(DCount("[IDBuyer]", "TBL_BUYER", "IDBuyer like'" & txtBuyer & "'")) > 0 Then

DoCmd.OpenForm "008 FRM VISUALIZZA BUYER", acNormal, , "IDBuyer like'*" & txtBuyer & "*'", acFormReadOnly

Else

MsgBox "Non è stato trovato nessun documento con ID Buyer=" & txtBuyer

End If

End Sub

Domanda: come posso estendere il tutto con più text box?

Supponiamo di avere 4 text box: txt1, txt2, txt3, txt4 con 4 option button.

Se flaggo su option 1, si attiva txt1 in cui mi sarà permesso scrivere (gli altri non saranno abilitati). Il codice sopra dovrà valere solo per il campo flaggato!!!!

Non so se mi sono spiegato bene....

Grazie!!!!

Giuseppe

Microsoft 365 e Office | Access | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento

Risposta accettata dall'autore della domanda

Anonimo
2013-01-24T15:28:03+00:00

Ciao signor Giuseppe Di Vico,

;-)

Prova così:

Private Sub Visualizza_Click()

Dim strWhere As String

    Select Case Frame95.Value

    Case O1.OptionValue

      strWhere = "[SAP Number]=" & CStr(txt1.Value)

    Case O2.OptionValue

      strWhere = "[Vendor Name]='" & txt2.Value & "'"

    Case O3.OptionValue

      strWhere = "[Vendor Code]=" & CStr(txt3.Value)

    Case O4.OptionValue

      strWhere = "[Buyer Code]='" & txt4.Value & "'"

    Case Else

      MsgBox "Qualcosa è andato storto!"

      Exit Sub

    End Select

    If DCount("*", "DB", strWhere) Then

      DoCmd.OpenForm "005 FRM Visualizza", acNormal, , strWhere, acFormReadOnly

    Else

      MsgBox "Non è stato trovato nessun documento con " & strWhere

    End If

End Sub

La risposta è stata utile?

0 commenti Nessun commento

9 risposte aggiuntive

Ordina per: Più utili
  1. Anonimo
    2013-01-24T12:35:22+00:00

    Maurizio un altra domanda per quanto riguarda il codice:

    posso utilizzare lo stesso codice che mi hai succerito, per aprire il form?

    Ovvero

    Private Sub Comando_Clik()

           Select Case .Frame95.Value

          Case .O1.OptionValue ' Oppure: 1

               If Nz(DCount("[txt1]", "DB", "[txt1]=" & txt1)) > 0 Then

             DoCmd.OpenForm "005 FRM Visualizza", acNormal, , "[txt1]="   &txt1,acFormReadOnly

    Else

    MsgBox "Non è stato trovato nessun documento con Sap Number=" & txtSAP

    End If

           Case.O2........

    Secondo te puo andar bene?????

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2013-01-24T12:09:53+00:00

    Ciao Giuseppe Di Vico,

    sì, sul Frame. Che io ho chiamato "fraOpts".

    Altra cosa... Quel Debug.Assert False lo puoi anche togliere.

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2013-01-24T12:04:58+00:00

    Grazie mille Murizio!

    si....solo dopo che è stato flaggato uno dei campi e quindi dopo aver scritto nella corrispondente text box clicco sul bottone in cui vorrei inserire il codice!!!

    Domanda: dove inserisco il codice che mi hai postato? Sul Frame??

    Grazie mille!!!

    Giuseppe

    La risposta è stata utile?

    0 commenti Nessun commento
  4. Anonimo
    2013-01-24T12:02:07+00:00

    Ciao Giuseppe Di Vico,

    un modo:

    Private Sub fraOpts_Click()

        With Me

          .txt1.Enabled = False

          .txt2.Enabled = False

          .txt3.Enabled = False

          .txt4.Enabled = False

          Select Case .fraOpts.Value

          Case .opt1.OptionValue ' Oppure: 1

            With .txt1

              .Enabled = True

              .SetFocus

            End With

          Case .opt2.OptionValue ' Oppure: 2

            With .txt2

              .Enabled = True

              .SetFocus

            End With

          Case .opt3.OptionValue ' Oppure: 3

            With .txt3

              .Enabled = True

              .SetFocus

            End With

          Case .opt4.OptionValue ' Oppure: 4

            With .txt4

              .Enabled = True

              .SetFocus

            End With

          Case Else

            Debug.Assert False

          End Select

        End With

    End Sub

    ... poi il codice dovrai eseguirlo quando l'utente completa il testo nella TextBox abilitata, giusto?

    La risposta è stata utile?

    0 commenti Nessun commento