Question : How to generate error message that contains a parameter?

Hi experts,

I'm trying to insert records from tbl_A to tbl_B. Each record in tbl_B contains a unique caseID. I want to prompt an error message if any of the records in tbl_A that I want to insert into tbl_B already exist in tbl_B. However, I want the message to show which record(s) are those already existed ones by revealing their caseID(s), which means the error message that I use need to contain a parameter instead of pure strings.  Moreover, I want to give two options for user to choose as either to proceed or to cancel. For the moment I can only come up with the following codes that display a simple message upon occurance and exits the function:

Sub UpdateTableB()

  Dim sGetSQL As String
  On Error GoTo Duplicate_Error

  sGetSQL = "INSERT INTO tbl_B(caseID, fld_1, fld_2, fld_3, fld_4, etc ) " _
          & "SELECT Mid(someStringThatContainsCaseID, 58, 8), fld_1, fld_2, fld_3, fld_4 " _
          & "FROM tbl_A " _
          & "WHERE fld_4 IS NOT NULL"
         
  CurrentDb.Execute sGetSQL, dbFailOnError

Duplicate_Exit:
  Exit Sub
 
Duplicate_Error:
  Select Case Err.Number
    Case 3022
    MsgBox "The case already exists. Do you still want to proceed?"
  End Select
 
GoTo Duplicate_Exit
 
End Sub


Can anyone help me to modify the codes so as to achieve my objectives?

Thank you very much!
 

Answer : How to generate error message that contains a parameter?



good morning...

if you wanted to show parameter on your message box.
here is the format...

this is just an example..but i know this will give u and idea...


sub showMessage()

        dim strFirstName as striin
        strFirstName  = "Alvin Doliente"

        'if you wanted to show this string on the message box...

        msgbox "HI " & strFirstName

        'the result message will be... "HI Alvin Doliente"

end sub

is this what u wanted to happen...

if you u have question let me know...

glad i could help..


game-master
Random Solutions  
 
programming4us programming4us