KJKAccess
asked on
Access 2003 to 2010 conversion issue...Object variable or with block variable not set
I have an Access db created in Access 2003 that needs to be converted to 2010. In general the db functions in 2010, but the database was able to send out an email with the click of a button in 2003. Now when I click the botton I get an error..."object variable or With block variable not set". This button runs off the below code. Any suggestions of what I need to do to make this functional in 2010? I would really appreciate it!
Option Compare Database
Private Sub Command5_Click()
Dim stDocName As String
Dim stLinkCriteria As String
On Error GoTo Err_Command5_Click
strsql = "select Title, Name, Email_Address into [tblLocalEmailFlow] from tblEmailFlow where [frm1-Step1] = 1;"
DoCmd.SetWarnings False
DoCmd.RunSQL strsql
DoCmd.RunMacro "mcrrefresh"
stDocName = "frmSendEmail"
stLinkCriteria = "[ID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Command5_Click:
Exit Sub
Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click
End Sub
Option Compare Database
Private Sub Command5_Click()
Dim stDocName As String
Dim stLinkCriteria As String
On Error GoTo Err_Command5_Click
strsql = "select Title, Name, Email_Address into [tblLocalEmailFlow] from tblEmailFlow where [frm1-Step1] = 1;"
DoCmd.SetWarnings False
DoCmd.RunSQL strsql
DoCmd.RunMacro "mcrrefresh"
stDocName = "frmSendEmail"
stLinkCriteria = "[ID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Command5_Click:
Exit Sub
Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click
End Sub
ASKER
I am sorry. I am not a programmer and the person that developed this is gone so if I seem like I don't know what I am talking about...I don't! Having shared that, I think I posted the wrong code. That is the code that opens the email form so the body and recipients can be added. This is the code that I get the error on... Is it still the same answer? Really sorry :(
Private Sub Command5_Click()
Dim firschar As Integer
Dim lastchar As Integer
Dim strlen As Integer
firstchar = 1
lastchar = InStr(firstchar, Me!EmailAddresses, ",")
strlen = Len(Me!EmailAddresses)
If lastchar = 0 Then
' MsgBox Me!EmailAddresses
Call NotesMailSend(Me!EmailAddr esses, Me!Text4, Me!EmailBody)
Else
Do While lastchar > 0
' MsgBox Mid(Me!EmailAddresses, firstchar, lastchar - firstchar)
Call NotesMailSend(Mid(Me!Email Addresses, firstchar, lastchar - firstchar), Me!Text4, Me!EmailBody)
firstchar = lastchar + 1
lastchar = InStr(firstchar, Me!EmailAddresses, ",")
Loop
' MsgBox Mid(Me!EmailAddresses, firstchar, strlen - firstchar + 1)
Call NotesMailSend(Mid(Me!Email Addresses, firstchar, strlen - firstchar + 1), Me!Text4, Me!EmailBody)
End If
DoCmd.Close
End Sub
Private Sub Form_Load()
Dim DB As Database
Dim rst As Recordset ' v.1: Rst as Table
Dim InRecord As Recordset
Dim recSelectbck As Integer
Dim PC_Qty As Long
Dim Gone_Neg As Boolean
Dim tt1 As Integer
Dim PrevProduct As String
Dim PrevLoc As String
Dim CurProduct As String
Dim firsttimethru As Boolean
Set DB = CurrentDb()
Set InRecord = DB.OpenRecordset("tblLocal EmailFlow" )
If InRecord.RecordCount = 0 Then
Exit Sub
End If
firsttimethru = True
InRecord.MoveLast
recSelectbck = InRecord.RecordCount
InRecord.MoveFirst
For tt1 = 1 To recSelectbck
If firsttimethru Then
Me![EmailAddresses] = InRecord![email_address]
Else
Me![EmailAddresses] = Me![EmailAddresses] & ", " & InRecord![email_address]
End If
firsttimethru = False
InRecord.MoveNext
Next tt1
eendofile:
Me![EmailBody] = [Process_Flow_Type] & ": Product Flow #" & [ID] & vbCr & "Reference Number = " & [Reference_Number] & vbCr & "Notes = " & [Reference_Number_Notes] & vbCr & "Hormel Code = " & [Hormel_Code_FG]
End Sub
Private Sub Command5_Click()
Dim firschar As Integer
Dim lastchar As Integer
Dim strlen As Integer
firstchar = 1
lastchar = InStr(firstchar, Me!EmailAddresses, ",")
strlen = Len(Me!EmailAddresses)
If lastchar = 0 Then
' MsgBox Me!EmailAddresses
Call NotesMailSend(Me!EmailAddr
Else
Do While lastchar > 0
' MsgBox Mid(Me!EmailAddresses, firstchar, lastchar - firstchar)
Call NotesMailSend(Mid(Me!Email
firstchar = lastchar + 1
lastchar = InStr(firstchar, Me!EmailAddresses, ",")
Loop
' MsgBox Mid(Me!EmailAddresses, firstchar, strlen - firstchar + 1)
Call NotesMailSend(Mid(Me!Email
End If
DoCmd.Close
End Sub
Private Sub Form_Load()
Dim DB As Database
Dim rst As Recordset ' v.1: Rst as Table
Dim InRecord As Recordset
Dim recSelectbck As Integer
Dim PC_Qty As Long
Dim Gone_Neg As Boolean
Dim tt1 As Integer
Dim PrevProduct As String
Dim PrevLoc As String
Dim CurProduct As String
Dim firsttimethru As Boolean
Set DB = CurrentDb()
Set InRecord = DB.OpenRecordset("tblLocal
If InRecord.RecordCount = 0 Then
Exit Sub
End If
firsttimethru = True
InRecord.MoveLast
recSelectbck = InRecord.RecordCount
InRecord.MoveFirst
For tt1 = 1 To recSelectbck
If firsttimethru Then
Me![EmailAddresses] = InRecord![email_address]
Else
Me![EmailAddresses] = Me![EmailAddresses] & ", " & InRecord![email_address]
End If
firsttimethru = False
InRecord.MoveNext
Next tt1
eendofile:
Me![EmailBody] = [Process_Flow_Type] & ": Product Flow #" & [ID] & vbCr & "Reference Number = " & [Reference_Number] & vbCr & "Notes = " & [Reference_Number_Notes] & vbCr & "Hormel Code = " & [Hormel_Code_FG]
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Second, If you are going to be tasked with updating someone elses code, you should learn to use a naming scheme for all of your controls.
Command5 means nothing to anyone, but cmd_SendEmail does. There are a number of naming schemes but I generally use a hybrid that uses a combination of ReddickReddick and Leszynski
Command5 means nothing to anyone, but cmd_SendEmail does. There are a number of naming schemes but I generally use a hybrid that uses a combination of ReddickReddick and Leszynski
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you all.
Dim strsql as String
John