get button name on 5 differ form

Andyleone

New member
Local time
Tomorrow, 05:18
Joined
Mar 27, 2014
Messages
7
Hello everyone, pardon me, if i make some mistake, because i still on learning curve.

anyway.. after searching on multiple forum i still had no answer how to get xform value because it on 5 differ forms.

so what i was looking for is a way to get the button name when button find on 5 different forms clicked:
if plausible specific only to below button

1) frmmchfpdata, cmdfind615
2) frmmchobdata, cmdfind617
3) frmmchu7data, cmdfind619
4) frmopddata, cmdfind215
5) frmopdflupdata, cmdfind217

below code on ok button at popup form named as frmsrhstudent.

Code:
[FONT=Tahoma][SIZE=2]
Private Sub Command0_Click()

Dim Srch As String
Dim Srchx As String
Dim xbtnname As String

Let [/SIZE][/FONT][FONT=Tahoma][SIZE=2][FONT=Tahoma][SIZE=2]xbtnname [/SIZE][/FONT] = ????  ....>  any idea? to refer thing said above, require function? if yes how?


Select Case [/SIZE][/FONT][FONT=Tahoma][SIZE=2][FONT=Tahoma][SIZE=2]xbtnname [/SIZE][/FONT]
'Go to below line based on Which button press(by it name) ?

'1)if button find on frmmchfpdata clicked
Case "cmdfind615"
   If IsNull(Text3) = True Then
      MsgBox "Please enter studentID", vbOKOnly
     Else
      Srch = "SELECT * FROM [qrymchfpdata] WHERE [studentID] LIKE '*" & Me.Text3 & "*';"
      Forms("frmmchfpdata").RecordSource = Srch
     End If
    
      If IsNull(Form_frmmchfpdata!studentIDtxt) = False Then
         MsgBox "Record found.", vbOKOnly
        Else
         MsgBox "Record not found! Displaying example record", vbRetryCancel
        End If
       
        If IsNull(Form_frmmchfpdata!studentIDtxt) = True Then
           Srchx = "SELECT * FROM [qrymchfpdata] WHERE REGDATE IN (SELECT min(REGDATE) FROM qrymchfpdata);"
           Forms("frmmchfpdata").RecordSource = Srchx
         End If
         
'2)if button find on frmmchobdata clicked
Case "cmdfind617"
   If IsNull(Text3) = True Then
      MsgBox "Please enter studentID", vbOKOnly
     Else
      Srch = "SELECT * FROM [qryfrmmchobdata] WHERE [studentID] LIKE '*" & Me.Text3 & "*';"
      Forms("frmmchobdata").RecordSource = Srch
     End If
    
      If IsNull(Form_frmmchobdata!studentIDtxt) = False Then
         MsgBox "Record found.", vbOKOnly
        Else
         MsgBox "Record not found! Displaying example record", vbRetryCancel
        End If
       
        If IsNull(Form_frmmchobdata!studentIDtxt) = True Then
           Srchx = "SELECT * FROM [qrymchobdata] WHERE REGDATE IN (SELECT min(REGDATE) FROM qrymchobdata);"
           Forms("frmmchobdata").RecordSource = Srchx
         End If
         
'3)if button find on frmmchu7data clicked
Case "cmdfind619"
   If IsNull(Text3) = True Then
      MsgBox "Please enter studentID", vbOKOnly
     Else
      Srch = "SELECT * FROM [qrymchu7data] WHERE [studentID] LIKE '*" & Me.Text3 & "*';"
      Forms("frmmchu7data").RecordSource = Srch
     End If
    
      If IsNull(Form_frmmchu7data!studentIDtxt) = False Then
         MsgBox "Record found.", vbOKOnly
        Else
         MsgBox "Record not found! Displaying example record", vbRetryCancel
        End If
       
        If IsNull(Form_frmmchu7data!studentIDtxt) = True Then
           Srchx = "SELECT * FROM [qrymchu7data] WHERE REGDATE IN (SELECT min(REGDATE) FROM qrymchu7data);"
           Forms("frmmchu7data").RecordSource = Srchx
         End If
         
'4)if button find on frmopddata clicked
   Case "cmdfind215"
   If IsNull(Text3) = True Then
      MsgBox "Please enter studentID", vbOKOnly
     Else
      Srch = "SELECT * FROM [qryopddata] WHERE [studentID] LIKE '*" & Me.Text3 & "*';"
      Forms("frmopddata").RecordSource = Srch
     End If
    
      If IsNull(Form_frmopddata!studentIDtxt) = False Then
         MsgBox "Record found.", vbOKOnly
        Else
         MsgBox "Record not found! Displaying example record", vbRetryCancel
        End If
       
        If IsNull(Form_frmopddata!studentIDtxt) = True Then
           Srchx = "SELECT * FROM [qryopddata] WHERE REGDATE IN (SELECT min(REGDATE) FROM qryopddata);"
           Forms("frmopddata").RecordSource = Srchx
         End If

'5)if button find on frmopdflupdata clicked
Case "cmdfind217"
   If IsNull(Text3) = True Then
      MsgBox "Please enter studentID", vbOKOnly
     Else
      Srch = "SELECT * FROM [qryopdflupdata] WHERE [studentID] LIKE '*" & Me.Text3 & "*';"
      Forms("frmopdflupdata").RecordSource = Srch
     End If
    
      If IsNull(Form_frmopdflupdata!studentIDtxt) = False Then
         MsgBox "Record found.", vbOKOnly
        Else
         MsgBox "Record not found! Displaying example record", vbRetryCancel
        End If
       
        If IsNull(Form_frmopdflupdata!studentIDtxt) = True Then
           Srchx = "SELECT * FROM [qryopdflupdata] WHERE REGDATE IN (SELECT min(REGDATE) FROM qryopdflupdata);"
           Forms("frmopdflupdata").RecordSource = Srchx
         End If
         
End Sub
[/SIZE][/FONT]
 
What's the point of your above code?
Only one piece of advice, give your controls meaningful names.
 
...and why do you want to get the name of a button? A button fires events (from which point you can get the name) so this exercise doesn't seem at all useful.
 
..Thank guy for advise, i just modified the vba code.. by assign the value to case "" it fixed.
 
..Thank guy for advise, i just modified the vba code.. by assign the value to case "" it fixed.

You think so?

That horrible code is due to misguided approach.

Also note that objects should not be referred to via their module name.
eg Form_frmmchobdata!studentIDtxt


If that form is closed when that reference is made, a hidden instance of it will be opened.


Refer to forms via the Forms collection if they are open or via CurrentProject!AllForms if it is not known if they are Open or Closed.

BTW The Let keyword was deprecated long ago.
 
... and the control names are not meaningful.

I wouldn't say that Let is deprecated, it's just optional now.
 

Users who are viewing this thread

Back
Top Bottom