Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 04-17-2019, 04:27 AM   #1
Alhakeem1977
Newly Registered User
 
Join Date: Jun 2017
Posts: 85
Thanks: 24
Thanked 0 Times in 0 Posts
Alhakeem1977 is on a distinguished road
Error 3061 Too few parameters Expected1.

Hi,
Trying to solve this issue with no success, to generate an email body with a table.

Below is my vba code and the query below the code:

When I remove the parameter from the query it works fine but with parameter, it dosesn't Error 3061

Code:
Private Sub cmdOpenEmail_Click()
On Error GoTo ErrorHandler

Dim strMsg As String
Dim iResponse As Integer

DoCmd.Beep
   strMsg = "Are you sure you want to proceed?" & Chr(10)
      strMsg = strMsg & ""
   iResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "Notice")
   If iResponse = vbNo Then
   Me.Undo
    
  DoCmd.Close acForm, "frmFileReqA", acSaveNo

  Else
 
  Me.Dirty = False

 '''''''''''''''''' tools -> refrence -> Microsoft outlook
Dim olApp As Outlook.Application
Dim olMail As MailItem
Dim mailbody As String
Dim rs As DAO.Recordset
' <br> used to insert a line ( press enter)
' create a table using html
' check the link below to know more about html tables
' http://www.w3schools.com/html/html_tables.asp
' html color code
'http://www.computerhope.com/htmcolor.htm or http://html-color-codes.info/
'bg color is used for background color
' font color is used for font color
'<b> bold the text  http://www.w3schools.com/html/html_formatting.asp
' &nbsp;  is used to give a single space between text
'<p style="font-size:15px">This is some text!</p> used to reduce for font size

'********************* created header of table
   mailbody = "<TABLE Border=""1"", Cellspacing=""0""><TR>" & _
   "<TD Bgcolor=""#2B1B17"", Align=""Center""><Font Color=#FCDFFF><b><p style=""font-size:18px"">A/C No.&nbsp;</p></Font></TD>" & _
   "<TD Bgcolor=""#2B1B17"", Align=""Center""><Font Color=#FCDFFF><b><p style=""font-size:18px"">Customer's Name&nbsp;</p></Font></TD>" & _
      "</TR>"
      

Set rs = CurrentDb.OpenRecordset("qryFileReqEmail", dbOpenDynaset)
rs.MoveFirst
Do While Not rs.EOF

              mailbody = mailbody & "<TR>" & _
               "<TD ><center>" & rs.Fields![Account Number].Value & "</TD>" & _
               "<TD><center>" & rs.Fields![Customer].Value & "</TD>" & _
                                   "</TR>"

rs.MoveNext
Loop
rs.Close

' <br> used to insert a line ( press enter)
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)
With olMail
.To = "#########@###.com"
.Cc = ""
.Subject = "Account File/s Physical Retrieval Request"
.HTMLBody = "Dear DMS <br><br> ""Kindly arrange to provide me with the physical Account file/s as per the below details: <br><br> " & mailbody & _
"</Table><br> <br>Your assistance in this matter would be highly appreciated.<br> <br>Regards, <br> <br> " & [Forms]![NavigationForm]![txtUserName] & ""
.Display
'.Send
 MsgBox "Your email has been generated successfully!"
End With
  
 
DoCmd.Close acForm, "frmFileReqA", acSaveNo
End If
Cleanup:
  Exit Sub

ErrorHandler:
  Select Case Err.Number
    Case 2501
      MsgBox "Email message was Cancelled."
    Case Else
      MsgBox Err.Number & ": " & Err.Description
  End Select
  Resume Cleanup

End Sub
Code:
SELECT Customerstbl.FID, [Branch] & "-" & [AccountNumber] AS [Account Number], Customerstbl.Customer, [Userlogin] & " - " & [UserName] AS [Requested by], tblFileReq.ReqPk, tblFileReq.IsActive
FROM tblUser INNER JOIN (Customerstbl INNER JOIN tblFileReq ON Customerstbl.FID = tblFileReq.[AccountNo]) ON tblUser.UserID = tblFileReq.ReqID
WHERE (((tblFileReq.IsActive)=True) AND ((tblFileReq.ReqID)=[Forms]![NavigationForm]![txtID]))
ORDER BY [Branch] & "-" & [AccountNumber], Customerstbl.AccountNumber;

Thanks a lot in acvance!

Alhakeem1977 is offline   Reply With Quote
Old 04-17-2019, 04:38 AM   #2
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 1,446
Thanks: 19
Thanked 362 Times in 354 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: Error 3061 Too few parameters Expected1.

Hi. Have I told you to try out Leigh’s Generic Recordset?
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Old 04-17-2019, 05:32 AM   #3
Alhakeem1977
Newly Registered User
 
Join Date: Jun 2017
Posts: 85
Thanks: 24
Thanked 0 Times in 0 Posts
Alhakeem1977 is on a distinguished road
Re: Error 3061 Too few parameters Expected1.

Quote:
Originally Posted by theDBguy View Post
Hi. Have I told you to try out Leighís Generic Recordset?
Thank you so much for your earliest response.
Unfortunately, I do not know how to use the function in the link, how do I link it to the data to be placed inside the email body as a table with some fixed text?

Sent from my HUAWEI NXT-L29 using Tapatalk

Alhakeem1977 is offline   Reply With Quote
Old 04-17-2019, 05:59 AM   #4
Alhakeem1977
Newly Registered User
 
Join Date: Jun 2017
Posts: 85
Thanks: 24
Thanked 0 Times in 0 Posts
Alhakeem1977 is on a distinguished road
Re: Error 3061 Too few parameters Expected1.

Quote:
Originally Posted by theDBguy View Post
Hi. Have I told you to try out Leighís Generic Recordset?
Sorry I did not mention that I am referring to Microsoft Access

Sent from my HUAWEI NXT-L29 using Tapatalk
Alhakeem1977 is offline   Reply With Quote
Old 04-17-2019, 06:00 AM   #5
essaytee
Need a good one-liner.
 
essaytee's Avatar
 
Join Date: Oct 2008
Location: Melbourne, Australia
Posts: 483
Thanks: 8
Thanked 107 Times in 103 Posts
essaytee is on a distinguished road
Re: Error 3061 Too few parameters Expected1.

With the form "NavigationForm" open, what happens when you run the query directly, do you still get the error message? By running directly, I mean double-clicking on the query name from the left-hand panel.
__________________
Steve.

I know UNIX, PASCAL, C, FORTRAN, COBOL, and nineteen other high-tech words.
essaytee is offline   Reply With Quote
Old 04-17-2019, 06:18 AM   #6
essaytee
Need a good one-liner.
 
essaytee's Avatar
 
Join Date: Oct 2008
Location: Melbourne, Australia
Posts: 483
Thanks: 8
Thanked 107 Times in 103 Posts
essaytee is on a distinguished road
Re: Error 3061 Too few parameters Expected1.

Similar to theDBGuy's link, check out QueryDefs.
__________________
Steve.

I know UNIX, PASCAL, C, FORTRAN, COBOL, and nineteen other high-tech words.
essaytee is offline   Reply With Quote
The Following User Says Thank You to essaytee For This Useful Post:
Alhakeem1977 (04-17-2019)
Old 04-17-2019, 07:02 AM   #7
gemma-the-husky
Super Moderator
 
gemma-the-husky's Avatar
 
Join Date: Sep 2006
Location: UK
Posts: 13,501
Thanks: 54
Thanked 958 Times in 926 Posts
gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all
Re: Error 3061 Too few parameters Expected1.

Am I right in thinking that this problem is caused by the resolution of the form reference. This bit.

((tblFileReq.ReqID)=[Forms]![NavigationForm]![txtID]))


I tend to get around this by using a function, but you could use tempvars

Not sure how you reference tempvars offhand, but this sort of thing

tempvars.txtid = [Forms]![NavigationForm]![txtID]

then in your query

((tblFileReq.ReqID)=tempvars.txtid]))

__________________
Dave (Male!)
Gemma was my dog

if a poster helps you, please click the scales at the top right of this posting, or use the thanks button alongside.
gemma-the-husky is offline   Reply With Quote
The Following User Says Thank You to gemma-the-husky For This Useful Post:
Alhakeem1977 (04-17-2019)
Old 04-17-2019, 07:20 AM   #8
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 1,446
Thanks: 19
Thanked 362 Times in 354 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: Error 3061 Too few parameters Expected1.

Quote:
Originally Posted by gemma-the-husky View Post
I tend to get around this by using a function,
Me too, like the one I linked to earlier.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
The Following User Says Thank You to theDBguy For This Useful Post:
Alhakeem1977 (04-17-2019)
Old 04-17-2019, 08:28 AM   #9
Gasman
Enthusiastic Amateur
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 3,270
Thanks: 358
Thanked 558 Times in 540 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: Error 3061 Too few parameters Expected1.

I use this syntax

Code:
tempvars("txtID")=231
though
Code:
tempvars!txtid = 221
works just as well.



Quote:
Originally Posted by gemma-the-husky View Post
Am I right in thinking that this problem is caused by the resolution of the form reference. This bit.

((tblFileReq.ReqID)=[Forms]![NavigationForm]![txtID]))


I tend to get around this by using a function, but you could use tempvars

Not sure how you reference tempvars offhand, but this sort of thing

tempvars.txtid = [Forms]![NavigationForm]![txtID]

then in your query

((tblFileReq.ReqID)=tempvars.txtid]))
__________________
Access novice. Sometimes trying to give something back.
Access 2007


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
The Following User Says Thank You to Gasman For This Useful Post:
Alhakeem1977 (04-17-2019)
Old 04-17-2019, 08:50 AM   #10
pbaldy
Wino Moderator
 
pbaldy's Avatar
 
Join Date: Aug 2003
Location: Nevada, USA
Posts: 32,708
Thanks: 11
Thanked 4,000 Times in 3,938 Posts
pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold
Re: Error 3061 Too few parameters Expected1.

Another simple solution is wrapping the form reference in the Eval() function:

tblFileReq.ReqID=Eval('[Forms]![NavigationForm]![txtID]')

The recordset should be able to open it with that in place.
__________________
Paul
Microsoft Access MVP

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
pbaldy is offline   Reply With Quote
The Following User Says Thank You to pbaldy For This Useful Post:
Alhakeem1977 (04-17-2019)
Old 04-17-2019, 09:54 AM   #11
Alhakeem1977
Newly Registered User
 
Join Date: Jun 2017
Posts: 85
Thanks: 24
Thanked 0 Times in 0 Posts
Alhakeem1977 is on a distinguished road
Re: Error 3061 Too few parameters Expected1.

This is to confirm that the issue is solved with Eval() function.

Quote:
Originally Posted by pbaldy View Post
Another simple solution is wrapping the form reference in the Eval() function:

tblFileReq.ReqID=Eval('[Forms]![NavigationForm]![txtID]')

The recordset should be able to open it with that in place.
Very cool, the code works great.

Code:
tblFileReq.ReqID=Eval('[Forms]![NavigationForm]![txtID]')
I honestly do not know how to thank you all, especially pbaldy.

Thank you all for your quick response.
Alhakeem1977 is offline   Reply With Quote
Old 04-17-2019, 09:59 AM   #12
Alhakeem1977
Newly Registered User
 
Join Date: Jun 2017
Posts: 85
Thanks: 24
Thanked 0 Times in 0 Posts
Alhakeem1977 is on a distinguished road
Re: Error 3061 Too few parameters Expected1.

Quote:
Originally Posted by gemma-the-husky View Post
Am I right in thinking that this problem is caused by the resolution of the form reference. This bit.

((tblFileReq.ReqID)=[Forms]![NavigationForm]![txtID]))


I tend to get around this by using a function, but you could use tempvars

Not sure how you reference tempvars offhand, but this sort of thing

tempvars.txtid = [Forms]![NavigationForm]![txtID]

then in your query

((tblFileReq.ReqID)=tempvars.txtid]))
Thank you so much for your response, for sure the Tempvars will solve the issue, all of you are experts.

The Eval function solves the issue.

Thanks again.
Alhakeem1977 is offline   Reply With Quote
Old 04-17-2019, 10:01 AM   #13
pbaldy
Wino Moderator
 
pbaldy's Avatar
 
Join Date: Aug 2003
Location: Nevada, USA
Posts: 32,708
Thanks: 11
Thanked 4,000 Times in 3,938 Posts
pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold
Re: Error 3061 Too few parameters Expected1.

Happy to help! There are certainly many ways to skin the proverbial cat. I hadn't seen Leigh's function before. Nice, as I would expect from him.
__________________
Paul
Microsoft Access MVP

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
pbaldy is offline   Reply With Quote
The Following User Says Thank You to pbaldy For This Useful Post:
Alhakeem1977 (04-17-2019)
Old 04-17-2019, 10:11 AM   #14
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 1,446
Thanks: 19
Thanked 362 Times in 354 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: Error 3061 Too few parameters Expected1.

Quote:
Originally Posted by pbaldy View Post
Happy to help! There are certainly many ways to skin the proverbial cat. I hadn't seen Leigh's function before. Nice, as I would expect from him.
And of course, one of its advantages is it doesn't require any of the existing queries to be changed at all. It just works! Cheers!

__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by theDBguy; 04-17-2019 at 10:17 AM.
theDBguy is offline   Reply With Quote
The Following User Says Thank You to theDBguy For This Useful Post:
Alhakeem1977 (04-17-2019)
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error 3061 - Too Few Parameters J0eydak!ng Modules & VBA 3 08-05-2013 10:16 AM
Error 3061 - Too Few parameters detrie Modules & VBA 3 07-09-2013 10:56 AM
RT Error 3061 : Too Few Parameters bballhermit Forms 9 03-21-2011 11:06 AM
Error 3061: Too Few Parameters Steve887 Modules & VBA 3 03-25-2008 07:48 PM
Too few parameters expected1 Rich Modules & VBA 2 07-06-2003 01:39 PM




All times are GMT -8. The time now is 12:37 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World