andrewf10
Registered User.
- Local time
- Today, 23:49
- Joined
- Mar 2, 2003
- Messages
- 114
Hi,
I have a piece of code which is something like that below. I have 12 command buttons (Button1, Button2 etc) which will use this same code, with 2 exceptions. The 'FollowOnCreated1' and 'Outstanding Tasks1' fieldnames will vary depending on the command button that's pressed. In other words, Button2 uses the 'FollowOnCreated2' and 'Outstanding Tasks2' fields in the same piece of code.
My question is this: Is there a way of just passing these 2 fields into this same piece of code, depending on which button calls it? This would be far more economical that copying the code 12 times and tweaking it for each On_Click event. I know having all these buttons and seperate fields is bad practice but they have to stay!
Any help much appreciated
Dim resp As Integer
resp = MsgBox("Are you sure you want to create a new reference job?", vbQuestion + vbYesNo, "Create new job?")
If resp = vbYes Then
'Comment: Create a new job and refer to the previous Job Number
Dim currJob As String
Dim currpmtask As String
Dim currtask As String
FollowOnCreated1 = "*" 'Comment: Indicates that follow-on job has been created
'Comment: Save current record before creating a new one...but only if the record has been changed (to avoid error)
If Me.Dirty = True Then
Call SaveRecord_Click
End If
currJob = [Job Number] 'Comment: Stores current job number
currpmtask = [schedule no] 'Comment: Stores current schedule number
currtask = [Outstanding Tasks1] 'Comment: Stores current task info
DoCmd.GoToRecord , , acNewRec
[Comments] = "This task was identified while carrying out Job Number " & currJob & " (Schedule No. " & currpmtask & ")"
[Category] = "non-Preventative Maintenance"
[Special Instructions] = currtask
DoCmd.GoToControl "[Job Number]"
'Comment: Cancel new job
Else
Exit Sub
End If
I have a piece of code which is something like that below. I have 12 command buttons (Button1, Button2 etc) which will use this same code, with 2 exceptions. The 'FollowOnCreated1' and 'Outstanding Tasks1' fieldnames will vary depending on the command button that's pressed. In other words, Button2 uses the 'FollowOnCreated2' and 'Outstanding Tasks2' fields in the same piece of code.
My question is this: Is there a way of just passing these 2 fields into this same piece of code, depending on which button calls it? This would be far more economical that copying the code 12 times and tweaking it for each On_Click event. I know having all these buttons and seperate fields is bad practice but they have to stay!
Any help much appreciated
Dim resp As Integer
resp = MsgBox("Are you sure you want to create a new reference job?", vbQuestion + vbYesNo, "Create new job?")
If resp = vbYes Then
'Comment: Create a new job and refer to the previous Job Number
Dim currJob As String
Dim currpmtask As String
Dim currtask As String
FollowOnCreated1 = "*" 'Comment: Indicates that follow-on job has been created
'Comment: Save current record before creating a new one...but only if the record has been changed (to avoid error)
If Me.Dirty = True Then
Call SaveRecord_Click
End If
currJob = [Job Number] 'Comment: Stores current job number
currpmtask = [schedule no] 'Comment: Stores current schedule number
currtask = [Outstanding Tasks1] 'Comment: Stores current task info
DoCmd.GoToRecord , , acNewRec
[Comments] = "This task was identified while carrying out Job Number " & currJob & " (Schedule No. " & currpmtask & ")"
[Category] = "non-Preventative Maintenance"
[Special Instructions] = currtask
DoCmd.GoToControl "[Job Number]"
'Comment: Cancel new job
Else
Exit Sub
End If