Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoKey

Status
Not open for further replies.

rjoshi2

Programmer
Sep 10, 2002
110
0
0
US
Can I create an AutoKey that will run the code below? If not how due I change the code so that it will run.

Private Sub CmdEditRecord_Click()
Me.AllowEdits = True
Me.CmdDeleteRecord.Enabled = True
Me.CmdUpdate.Enabled = True
Me.frmSubCommitRegDataSheet.Form.AllowEdits = True
Me.frmSubCommitRegDataSheet.Form.AllowDeletions = True
Me.frmSubCommitRegDataSheet.Form.AllowAdditions = True
End Sub

Thank You,
rjoshi2
 
An AUTOKEY entry can do a RUNCODE action, given a FUNCTION to run. Place your function in a module, and set an autokey keystroke to run that function.

Your function NEED not return a value - you could just change your SUBs to FUNCTIONs in your example.

Jim


Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
My questuion is how do I change this code so it will work:

Public Function EditRecordMacro()
Me!frmCommitRegMain.Form.AllowEdits = True
Me!frmCommitRegMain.Form.CmdDeleteRecord.Enabled = True
Me!frmCommitRegMain.Form.CmdUpdate.Enabled = True
Me!frmSubCommitRegDataSheet.Form.AllowEdits = True
Me!frmSubCommitRegDataSheet.Form.AllowDeletions = True
Me!frmSubCommitRegDataSheet.Form.AllowAdditions = True
End Function

When I press Ctrl+E (AutoKeys) I get an action failed error.

Thank You,
rjoshi2
 
First off, I'd use the more generic "Screen.ActiveForm" object rather than ME in a public function. I think it's more reliable.

Have you any idea which ACTION failed?

The syntax for referring to a subform is this:

MainForm.SubFormControlName!Form

Try the above mods and see what happens.









Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
Hi Jim,

I won't buy into this problem since I don't have a better answer but in following this thread I am pleased to see a plug for generic object syntax. Although I understand the convenience of 'Me' I always get confused by its ubiquitous use in these forums, especially when the code quoted is often only a fragment.

Intuitas
 
Help please. I am creating an AutoKeys macro. The code works fine without the if statements. What is wrong with my if statements. Any help would be appreciated.

Thank You,
rjoshi

Public Function EditRecordMacro()

If Forms.Name = "frmCommitRegMain" And Forms("frmCommitRegMain").Form!frmSubCommitRegDataSheet.Form.Visiable = True Then

Forms("frmCommitRegMain").Form.AllowEdits = True
Forms("frmCommitRegMain").Form.CmdDeleteRecord.Enabled = True
Forms("frmCommitRegMain").Form.CmdUpdate.Enabled = True
Forms("frmCommitRegMain").Form!frmSubCommitRegDataSheet.Form.AllowEdits = True
Forms("frmCommitRegMain").Form!frmSubCommitRegDataSheet.Form.AllowDeletions = True
Forms("frmCommitRegMain").Form!frmSubCommitRegDataSheet.Form.AllowAdditions = True

ElseIf Forms.Name = "frmCommitRegMain" Then

Forms("frmCommitRegMain").Form.AllowEdits = True
Forms("frmCommitRegMain").Form.CmdDeleteRecord.Enabled = True
Forms("frmCommitRegMain").Form.CmdUpdate.Enabled = True

ElseIf Forms.Name = "frmCommitRegDataSheet" Then

Forms("frmCommitRegDataSheet").Form!frmSubCommitRegDataSheet.Form.AllowEdits = True
Forms("frmCommitRegDataSheet").Form!frmSubCommitRegDataSheet.Form.AllowDeletions = True
Forms("frmCommitRegDataSheet").Form!frmSubCommitRegDataSheet.Form.AllowAdditions = True

Else

Exit Function

End If
End Function
 
I'm not sure if this is the only thing, but check your misspelling of the word VISIBLE in the second line.

Also, this seems rather complex to be putting in an autokeys macro - are you sure you want to do this?

IMHO, anyway.

Jim

Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
I have gotten it to work by using the code below. The only problem I am having is if use the autokey and frmCommitRegMain is not open I get any macro error message. I also get this message if open frmCommitRegDataSheet this form directly (not using the command button in frmCommitRegMain) and try to use the autokey. Any help in resolving these problems would be appreciated.

Thank You,
rjoshi

Public Function EditRecordMacro()
If Forms.Application.CurrentObjectName = "frmCommitRegMain" And Forms("frmCommitRegMain").Form!frmSubCommitRegDataSheet.Form.Visible = True Then
Forms("frmCommitRegMain").Form.AllowEdits = True
Forms("frmCommitRegMain").Form.CmdDeleteRecord.Enabled = True
Forms("frmCommitRegMain").Form.CmdUpdate.Enabled = True
Forms("frmCommitRegMain").Form!frmSubCommitRegDataSheet.Form.AllowEdits = True
Forms("frmCommitRegMain").Form!frmSubCommitRegDataSheet.Form.AllowDeletions = True
Forms("frmCommitRegMain").Form!frmSubCommitRegDataSheet.Form.AllowAdditions = True
ElseIf Forms.Application.CurrentObjectName = "frmCommitRegMain" Then
Forms("frmCommitRegMain").Form.AllowEdits = True
Forms("frmCommitRegMain").Form.CmdDeleteRecord.Enabled = True
Forms("frmCommitRegMain").Form.CmdUpdate.Enabled = True
ElseIf Forms.Application.CurrentObjectName = "frmCommitRegDataSheet" Then
Forms("frmCommitRegDataSheet").Form!frmSubCommitRegDataSheet.Form.AllowEdits = True
Forms("frmCommitRegDataSheet").Form!frmSubCommitRegDataSheet.Form.AllowDeletions = True
Forms("frmCommitRegDataSheet").Form!frmSubCommitRegDataSheet.Form.AllowAdditions = True
Else
Exit Function
End If
End Function
 
Your function needs FIRST, to check if frmCommitRegMain is open and has the focus. If it's NOT, you need to decide what to do - open the form and do the stuff, or display a message that the form isn't open and let the user decide what do to.

I think part of the problem may be that you want to carry out a process that is very form-specific, whereas the idea of the AutoKey macro is to assign "shortcuts" to specific keys that will ALWAYS be generic in nature. For example, my AutoKeys macro sets up F7 and F8 to toggle between form design and form view, F4 and F5 to toggle between query-run and query-design, and so on.

Your process to make a subform visible and set various editing parameters would really be better off in the code for the main form itself, triggered by a Command button or other interface object on the form.

The whole process could then be trimmed down to something like this:

Private Function EditRecordMacro()
' **************************
' if the subform is visible, do all this stuff
' *****************************
if me!frmSubCommitRegDataSheet.Form.Visible = True Then
Me.AllowEdits = True
Me.CmdDeleteRecord.Enabled = True
Me.CmdUpdate.Enabled = True
Me!frmSubCommitRegDataSheet.Form.AllowEdits = True
Me!frmSubCommitRegDataSheet.Form.AllowDeletions = True
me!frmSubCommitRegDataSheet.Form.AllowAdditions = True
' *****************************
' If the subform is NOT visible, do this
stuff
' *****************************

Else
me.AllowEdits = True
me.CmdDeleteRecord.Enabled = True
me.CmdUpdate.Enabled = True

' the above three lines seem to do the same thing as the first part????
[/blue]
End If
End Function

I got confused reading your code - all the ELSEIF statements seemed to be doing the same thing regardless - setting the Allowedits, AllowDeletions and AllowAdditions to true and enabling the two command buttons...

What do you REALLY want to do with this function?





Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
My program is working fine now. If any has any suggestion on how I could possible improve the code I would appreciated.

Thank You,
rjoshi2

Code:
Public Function EditRecordMacro()
If IsFormOpened("frmCommitRegMain") Then
If Forms("frmCommitRegMain").Form!frmSubCommitRegDataSheet.Form.Visible = True Then
Forms("frmCommitRegMain").Form.AllowEdits = True
Forms("frmCommitRegMain").Form.CmdDeleteRecord.Enabled = True
Forms("frmCommitRegMain").Form.CmdUpdate.Enabled = True
Forms("frmCommitRegMain").Form!frmSubCommitRegDataSheet.Form.AllowEdits = True
Forms("frmCommitRegMain").Form!frmSubCommitRegDataSheet.Form.AllowDeletions = True
Forms("frmCommitRegMain").Form!frmSubCommitRegDataSheet.Form.AllowAdditions = True
Else
Forms("frmCommitRegMain").Form.AllowEdits = True
Forms("frmCommitRegMain").Form.CmdDeleteRecord.Enabled = True
Forms("frmCommitRegMain").Form.CmdUpdate.Enabled = True
End If
End If
If IsFormOpened("frmCommitRegDataSheet") Then
Forms("frmCommitRegDataSheet").Form!frmSubCommitRegDataSheet.Form.AllowEdits = True
Forms("frmCommitRegDataSheet").Form!frmSubCommitRegDataSheet.Form.AllowDeletions = True
Forms("frmCommitRegDataSheet").Form!frmSubCommitRegDataSheet.Form.AllowAdditions = True
End If
End Function

Public Function IsFormOpened(strFrm As String) As Boolean
Dim i As Integer
For i = 0 To Forms.Count - 1
If Forms(i).Name = strFrm Then
IsFormOpened = True
Exit Function
End If
Next i
IsFormOpened = False
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top