Discussion Locked

Using procedure arguments

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am having a problem passing an argument to an Access 2000 (DAO) procedure named ?Sub CreateActiveWOA(strTaskID As String)?.

My procedure is called from the click event on an ?OK? button named ?cmdOK? on a form named ?AMDT? (for Active Maintenance Department Tasks). The click event reads as follows:

Private Sub cmdOK_Click()
On Error GoTo Err_cmdOK_Click

'EXECUTE THE APPROPRIATE PROCEDURE FOR THE USER SELECTED OPERATION.
Select Case dmdtTaskType
Case "WOA"
Call CreateActiveWOA(Forms!AMDT.dmdtPK)
Case "WOB"
Call CreateActiveWOB(Forms!AMDT.dmdtPK)
Case "WON"
Call CreateActiveWON(Forms!AMDT.dmdtPK)
Case "WRA"
Call CreateActiveWRA(Forms!AMDT.dmdtPK)
Case "WRB"
Call CreateActiveWRB(Forms!AMDT.dmdtPK)
Case "WRN"
Call CreateActiveWRN(Forms!AMDT.dmdtPK)
Case Else
MsgBox "You MUST select a Task Type and load its Posting data before activation."
dmdtTaskType.SetFocus
End Select

Exit_cmdOK_Click:
Exit Sub

Err_cmdOK_Click:
MsgBox Err.Description
Resume Exit_cmdOK_Click

End Sub

dmdtPK is a Combo box on AMDT where available Primary Key values from a WOA Table (for Work Orders, Automotive) are selected. The first field on AMDT is dmdtTaskType where the user selects on of the six options specified within my select case statement. The first part of my procedure reads as follows:

8 replies

by donq

Sub CreateActiveWOA(strTaskID As String)

'ADD AN AUTOMOTIVE WORK ORDER TO THE ACTIVE TASKS LIST
'AFTER THE DISPATCHER SELECTS A TASK ID AND MECHANIC.

'ENABLE PROCEDURAL ERROR HANDLING.
On Error GoTo CreateActiveWOA_Err

'DECLARE AND INITIALIZE THE CURRENT DATABASE AS THE DATABASE TO USE.
Dim DB As Database
Set DB = CurrentDb()

DoCmd.Hourglass True

'DECLARE TEMPORARY RECORDSET VARIABLES TO REPRESENT THE VARIOUS RECORDS TO ARCHIVE.
Dim Tgt As Recordset 'Object Model's "DlyMaintDeptTasks" (target) TABLE.
Dim Src As Recordset 'Object Model's "WOA" (source) TABLE.

'OPEN THE TARGET RECORDSET USED WITHIN THIS PROCEDURE.
Set Tgt = DB.OpenRecordset("DlyMaintDeptTasks", dbOpenDynaset)

'DECLARE PROCEDURE STRING MANAGEMENT VARIABLES.
Dim Sqlstr As String 'SQL Strings.
Dim MBstr As String 'Message Box Strings.

'PUT SQL STATEMENT IN STRING FORM TO LOAD THE PROCEDURE SOURCE TABLE
'BEFORE OPENING THE SOURCE RECORDSET.
Sqlstr = "SELECTWOA.* FROM WOA WHERE WOA.woaPK= 'strTaskID';"
Set Src = DB.OpenRecordset(Sqlstr, dbOpenDynaset) 'WITH UNRESTRICTED CURSOR MOVEMENT.

'ADD A NEW ACTIVE TASK FOR THE SELECTED AUTOMOTIVE WORK ORDER.
Tgt.MoveLast 'MOVE TO A BLANK RECORD
Tgt.AddNew 'CREATE A NEW TARGET TABLE RECORD.

'POST SOURCE VALUES INTO THE TARGET TABLE.
Tgt!dmdtTaskType = "WOA"
Tgt!dmdtPK = Src!woaPK
Tgt!dmdtTime = Src!woaTime
Tgt!dmdtFKv = Src!woaFKv Tgt!dmdtVM = Src!woaVM
Tgt!dmdtDesc = Src!woaDesc
Tgt!dmdtPRP = Src!woaPRP
Tgt!dmdtPRL = Src!woaPRL
Tgt!dmdtLuid1 = Src!woaLuid
Tgt!dmdtUpd1 = Src!woaUpd
Tgt!dmdtFKemp = [Forms]![AMDT].[dmdtFKemp]
Tgt!dmdtLuid = CurrentUser()
Tgt!dmdtUpd = Now()

'INSERT THIS RECORD INTO THE "DlyMaintDeptTasks" TABLE.
Tgt.Update

'DELETE THE WOA TABLE RECOR

by sixfourtykilo

I cannot really determine which way you are headed with this code since it is obvious that lines are missing and so is additional information. One thing that you can try doing is trapping for the error in a msgbox. Also, it looks like you are trying to get a value from an object on the form, instead of using "Forms!AMDT.dmdtPK", assign it to a string, or, add .caption at the end of it. Like I said I don't have enough information, but I hope this helps. Feel free to email me.

640k

by donq

EVERY line of code is shown and the part u question is working fine?? Thanks for trying.

by andrew

Your line:

Sqlstr = "SELECT WOA.* FROM WOA WHERE WOA.woaPK= 'strTaskID';"

looks like you have the variable as part of the string literal. try:

Sqlstr = "SELECT WOA.* FROM WOA WHERE WOA.woaPK= '" & strTaskID & "';"

by donq

Andrew - you are correct stating strTaskID is a variable and it is initialized as a string including its leading and trailing quote marks.

I can't place your suggested quote marks within the string being constructed as the 1st single quote after the your suggested double quote turns everything following it into comments. Please try again - you are very close.

by andrew

I don't want to disbelieve you, but in VB single quotes within double quotes are legal and are not interpreted as comments. I pasted my answer into VB and it worked perfectly. Please ensure that you have the closing double quote after the single quote.

by donq

Thanks - I also ad to import a "Varient" to eliminate the extra double quotes.

This discussion is closed to new replies.