ODBC Query param: Weird access violation setting param value

Hello,

If I could once again ask your indulgence, here is a problem setting the
input parameter for a stored procedure of an Access database called from
MFC.

The CRecordset-derived class for the Query is named CQueryWorkDaysSet,
and the parameter variable is named m_DateParam. There is an Access
Violation when the user tries to set the parameter just prior to a
Requery() call. (Note that contrary to the documentation, it was not
necessary to splice together this class from 2 other Tables. The
ClassWizard found the Query as another Table in the database. I simply
clicked it rather than one of the source Tables.)

Thanks very much,
Rick Lee

Here are relevant pieces of code (Look down to see the Access Violation
point.):
CQueryWorkDaysSet::CQueryWorkDaysSet(CDatabase* pdb)
 : CRecordset(pdb)
{
 //{{AFX_FIELD_INIT(CQueryWorkDaysSet)
 m_Work_Period_Number = 0;
 m_Project_Number = 0;
 m_Work_Day_Number = 0;
 m_nFields = 5;
 //}}AFX_FIELD_INIT
 m_nDefaultType = dynaset;
 m_nParams = 1;
 CTime localDate(1971, 1, 1, 0, 0, 0);
 m_DateParam = localDate;     // <--------- WORKS FINE TO INIT.
}

CString CQueryWorkDaysSet::GetDefaultConnect()
{
 return _T("ODBC;DSN=aTimeSheet2");
}

CString CQueryWorkDaysSet::GetDefaultSQL()
{
 return _T("{CALL WorkDay2WorkPeriods (?)}");
}

void CQueryWorkDaysSet::DoFieldExchange(CFieldExchange* pFX)
{
 pFX->SetFieldType( CFieldExchange::param );
 RFX_Date (pFX, _T("[Work Days].[Date]"), m_DateParam);

 //{{AFX_FIELD_MAP(CQueryWorkDaysSet)
 pFX->SetFieldType(CFieldExchange::outputColumn);
 RFX_Long(pFX, _T("[Work Period Number]"), m_Work_Period_Number);
 RFX_Long(pFX, _T("[Project Number]"), m_Project_Number);
 RFX_Date(pFX, _T("[Start Time]"), m_Start_Time);
 RFX_Date(pFX, _T("[End Time]"), m_End_Time);
 RFX_Long(pFX, _T("[Work Day Number]"), m_Work_Day_Number);
 //}}AFX_FIELD_MAP
}

void CQueryWorkDaysSet::RefreshWorkDay(int year, int month, int day)
{
 CTime localDate(year, month, day, 0, 0, 0);
 m_DateParam = localDate;               // <------- ACCESS VIOLATION
 this->Requery();
}

Other relevant code:

// From my Document's OnNewDocument():
 if (!this->m_queryWorkDaysSet.Open()) {
  AfxMessageBox("Could not open Work Days Query.");
  return FALSE;
 }

// From my View:
void CDayView::OnUpdate(CView *pSender, LPARAM lHint, CObject *pHint)
{
 currentDay   = this->GetDocument()->GetCurrentDay();
 currentMonth = this->GetDocument()->GetCurrentMonth();
 currentYear  = this->GetDocument()->GetCurrentYear();
 pQueryWkDays->RefreshWorkDay(currentYear, currentMonth, currentDay);
 CScrollView::OnUpdate(pSender, lHint, pHint);
}


0
Rick7596 (41)
4/21/2004 10:37:51 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
474 Views

Similar Articles

[PageSpeed] 55

Rick Lee <Rick@Custom-Made-SoftwareNOSPAM.com> wrote in message news:<4086F7BF.677138C0@Custom-Made-SoftwareNOSPAM.com>...
> Hello,
> 
> If I could once again ask your indulgence, here is a problem setting the
> input parameter for a stored procedure of an Access database called from
> MFC.
> 
> The CRecordset-derived class for the Query is named CQueryWorkDaysSet,
> and the parameter variable is named m_DateParam. There is an Access
> Violation when the user tries to set the parameter just prior to a
> Requery() call. (Note that contrary to the documentation, it was not
> necessary to splice together this class from 2 other Tables. The
> ClassWizard found the Query as another Table in the database. I simply
> clicked it rather than one of the source Tables.)
> 
> Thanks very much,
> Rick Lee
> 
> Here are relevant pieces of code (Look down to see the Access Violation
> point.):
> CQueryWorkDaysSet::CQueryWorkDaysSet(CDatabase* pdb)
>  : CRecordset(pdb)
> {
>  //{{AFX_FIELD_INIT(CQueryWorkDaysSet)
>  m_Work_Period_Number = 0;
>  m_Project_Number = 0;
>  m_Work_Day_Number = 0;
>  m_nFields = 5;
>  //}}AFX_FIELD_INIT
>  m_nDefaultType = dynaset;
>  m_nParams = 1;
>  CTime localDate(1971, 1, 1, 0, 0, 0);
>  m_DateParam = localDate;     // <--------- WORKS FINE TO INIT.
> }
> 
> CString CQueryWorkDaysSet::GetDefaultConnect()
> {
>  return _T("ODBC;DSN=aTimeSheet2");
> }
> 
> CString CQueryWorkDaysSet::GetDefaultSQL()
> {
>  return _T("{CALL WorkDay2WorkPeriods (?)}");
> }
> 
> void CQueryWorkDaysSet::DoFieldExchange(CFieldExchange* pFX)
> {
>  pFX->SetFieldType( CFieldExchange::param );
>  RFX_Date (pFX, _T("[Work Days].[Date]"), m_DateParam);
> 
>  //{{AFX_FIELD_MAP(CQueryWorkDaysSet)
>  pFX->SetFieldType(CFieldExchange::outputColumn);
>  RFX_Long(pFX, _T("[Work Period Number]"), m_Work_Period_Number);
>  RFX_Long(pFX, _T("[Project Number]"), m_Project_Number);
>  RFX_Date(pFX, _T("[Start Time]"), m_Start_Time);
>  RFX_Date(pFX, _T("[End Time]"), m_End_Time);
>  RFX_Long(pFX, _T("[Work Day Number]"), m_Work_Day_Number);
>  //}}AFX_FIELD_MAP
> }
> 
> void CQueryWorkDaysSet::RefreshWorkDay(int year, int month, int day)
> {
>  CTime localDate(year, month, day, 0, 0, 0);
>  m_DateParam = localDate;               // <------- ACCESS VIOLATION
>  this->Requery();
> }
> 
> Other relevant code:
> 
> // From my Document's OnNewDocument():
>  if (!this->m_queryWorkDaysSet.Open()) {
>   AfxMessageBox("Could not open Work Days Query.");
>   return FALSE;
>  }
> 
> // From my View:
> void CDayView::OnUpdate(CView *pSender, LPARAM lHint, CObject *pHint)
> {
>  currentDay   = this->GetDocument()->GetCurrentDay();
>  currentMonth = this->GetDocument()->GetCurrentMonth();
>  currentYear  = this->GetDocument()->GetCurrentYear();
>  pQueryWkDays->RefreshWorkDay(currentYear, currentMonth, currentDay);
>  CScrollView::OnUpdate(pSender, lHint, pHint);
> }

This is likely to be a problem with m_DateParam::operator= so the
problem is you think you have posted relevant code but you haven't
even told us how you define m_DateParam (as far as I can see).
0
rquirk1 (133)
4/23/2004 9:54:35 AM

Headache wrote:

> This is likely to be a problem with m_DateParam::operator= so the
> problem is you think you have posted relevant code but you haven't
> even told us how you define m_DateParam (as far as I can see).

m_DateParam is a CTime member of the class initialized in the constructor:
CQueryWorkDaysSet::CQueryWorkDaysSet(CDatabase* pdb)
 : CRecordset(pdb)
{
 //{{AFX_FIELD_INIT(CQueryWorkDaysSet)
 m_Work_Period_Number = 0;
 m_Project_Number = 0;
 m_Work_Day_Number = 0;
 m_nFields = 5;
 //}}AFX_FIELD_INIT
 m_nDefaultType = dynaset;
 m_nParams = 1;
 CTime localDate(1971, 1, 1, 0, 0, 0); // init to arbitrary time
 m_Start_Time = localDate;         // <------- output member
 m_End_Time   = localDate;        // <------- output member
 m_DateParam  = localDate;       // <------- input parameter
}


0
Rick7596 (41)
4/26/2004 11:05:09 PM
Reply:

Similar Artilces:

Business Portal Error-SQL server does not exist or access denied
Hi, We are running business portal 4.0 for one of our customer. It was running correctly, however, they have changed the SQL server port (previously it was set as default 1433). After that the business portal becomes very slow and while creating a new request (purchase requisition) if we open the item pop up; it is showing exception "SQL Server does not exist or access denied...." Can any body tell me how can I provide the new port number to business portal connection to the database. Thanks and Regards, Waliullah, Thanks for using the newsgroups. I have a...

What's happened to the findfirst function in Access 2010?
I have a working Access 2007 Application which is now failing miserably in 2010. It hinges on location the first available working document in a table runing the following VBA code: With Me.Recordset .FindFirst "([fld1] + [fld2]) = 0" If .NoMatch Then .FindLast "([fdl1] + [fld2]) <> 0" Exit Sub End If .... FURTHER PROCESSING ... What must I do to correct this? Go through a record by record search? End With In 2007, this works correctly, stopping at the appropriate record (approc. rec 1385 in the recordset...

visual basic
Hi, I trying to retrieve values from a table to calculate the 14days average value of a stock closing price. However, i encounter some problem as stated beside the code as follows: Function DaysAvgs() 'Calculate the average value of a given value. Dim db As DAO.Database Dim rst As DAO.Recordset Dim varBookmark As Variant Dim numAve, numDaysAvg As Double Dim intA, intB, lngCount As Integer Set db = CurrentDb 'Open Table Set rst = db.OpenRecordset("SGX Individual Historical", dbOpenTable) rst.MoveFirst Do While Not rst.EOF intA = 1 intB = 0 varBookmark = rst.Bookmark n...

open two different Access reports
Hi, I was wondering if i can get some help here. I have two different reports that i want to open when a user clicks a button to view the reports for printing. Is there any way of popping them up at the same time in VBA? Thank you in advance Associates wrote: >Hi, > >I was wondering if i can get some help here. I have two different reports >that i want to open when a user clicks a button to view the reports for >printing. Is there any way of popping them up at the same time in VBA? > >Thank you in advance Yes. Call the DoCmd.OpenReport command twic...

Access 2007 and Vista code problem
I am developing a database on a XP SP2 machine. On a form I have created some buttons with event procedures that run 2 queries and open a form. I sent the db to someone running Access 2007 on a Vista machine and nothing happens when she clicks the buttons and there are no messages. I know nothing about Vista so thanks in advance for any help. Tim Might be a reference problem, have them open the open a code window and click tools references. See what says missing and tell them what should be there, Add it and it should work. Duff "Tim Reid" <TimReid@discussions.micr...

Web query timeout setting.
Dear Group, I fill an Excel table using data that I take from an Internet site. Unfortunately, this site is very slow and so I often get a "query did not provide any data" error message. How can I increment the default web query timeout limit? Thanks in advance, Enrico. ...

.pdf save as settings
Hi, In Office 2007 Pro is there a way to change the settings such as preventing content copying etc. when saving a file to pdf? I have been trialling Open Office, alongside Office 2007 Pro (full version not a trial), which allows access to these settings but I can't see a way to do it in MS Office. -- Chas MS Office doesn't do that. Chass wrote: > Hi, In Office 2007 Pro is there a way to change the settings such as > preventing content copying etc. when saving a file to pdf? I have been > trialling Open Office, alongside Office 2007 Pro (full version not...

IsOutLookClient() returns wrong value
IsOutLookClient() returns wrong value when both web client of crm and outlook client are running on the same workstation It looks like the same cookie(used for determining what client is running) is used by the sessions of each client. Look for "LightClient" in IsOutlookWorkstationClient() in global.js Oeps...I seem to have made a wrong assumption... Between the to clients IsOutlookClient() seems to work ok... But in outlook client the IsOutlookClient() function gives false for me...after I have opened a page from the Microsoft Crm folder structure... On another workstation it...

Setting up a new e-mail account
I'm trying to set up my yahoo account so that I receive my e-mail messages in my Outlook Inbox. I went to Accounts, and servers, and put in mail.yahoo.com for incoming mail (POP3) and smtp.yahoo.com for outgoing mail (smtp). When I click on the send/receive button I get an error message. Dave <anonymous@discussions.microsoft.com> wrote: > I'm trying to set up my yahoo account so that I receive > my e-mail messages in my Outlook Inbox. I went to > Accounts, and servers, and put in mail.yahoo.com for > incoming mail (POP3) and smtp.yahoo.com for outgoing mail &...

changing values of one field based on another
How can I best change the values of one field in a table based on values of another field of the same table. We have an existing table of thousands of entries and I would like to use the following logic to populate a new boolean field. If field1 = "Done" Then BooleanFieldCompleted = True I have some Excel VBA experience but limited Access. I dont want to do this manually! Any assistance appreciated. In general, you'd use an Update query. However, in this case I don't see why you'd need such a field. Why not just create a query with a computed field that returns True...

Using Access 2003 on client to see Sharepoint 2007
Testing a Sharepoint environment and I can easily manipulate and run the database from Access 2007, but when I try to use Access 2003 it wants me to save the database to a location. The Access 2003 has the compatiblity pack, but it seems to not work when I download it. So the question is using Sharepoint 2007 and posting the Access 2007 format to it, can a user go to the sharepoint site and use a 2003 Access database that has the compatibility pack and open without having to download it? -- Message posted via http://www.accessmonster.com Send check for $500.00 to: David A Jenn...

I would like to know how to set up a 'fill in the blanks' form?
I would like to set up a templet of sorts to fill in the blanks for certificates. ...

compact database in VBA access 2007
Hello, I have recently upgrade to office 2007 from office 2003. To compact a database from within the database itself, I used the follwing code. Unfortunately it no longer works in access 2007. Is there some similar code that will work? Public Function FncCompactTheCurrentDB() CommandBars("Menu Bar"). _ Controls("Tools"). _ Controls("Database utilities"). _ Controls("Compact and repair database..."). _ accDoDefaultAction End Function Thank You, SL On Thu, 28 Jan 2010 17:34:01 -0800, SL <SL@discussions.microsoft....

I want to add a mail account without setting a SMTP server. Is it possible?
I want to add a second mail account that is outside my company. Since the company firewall does not allow us to connect to SMTP-servers I want to add this account without setting the SMTP propertiy. I cannot specify the company server as it is an Exchange server and the outside one an IMAP one. Currently I have specified the outside SMTP server since outook does not allow me to add an account wihtout setting this. I keep getting annoying error messages as my computer can't connect to the outside SMTP. Any one know a way around this? cheers, mortb The company server has SMTP enabled, u...

How to add a button to restore all altered cells original values?
I want to add a reset button to an excel spreadsheet that will restore the values of all changed cells to the original saved ones. Any help would be appreciated. Thanks Dawn Hi this would require quite some VBA code as you somehow have to store the original values for example on a separate hidden sheet -- Regards Frank Kabel Frankfurt, Germany "Dawnybros" <Dawnybros@discussions.microsoft.com> schrieb im Newsbeitrag news:3340601E-16EE-4296-8F50-B0BAC18EA387@microsoft.com... > I want to add a reset button to an excel spreadsheet that will restore the > values of all ...

LDAP Write access?
My ldap server allows Write access to entries - and a few clients now support this. Any plugins available for Outlook to allow this too? Thanks None that I'm aware of. -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Need Help with Common Tasks? http://www.outlook-tips.net/beginner/ Outlook 2007: http://www.slipstick.com/outlook/ol2007/ Outlook Tips by email: dailytips-subscribe-request@lists.outlooktips.net Subscribe to Exchange Messaging Outlook newsletter: EMO-NEWSLETTER-SUBSCRIBE-REQUEST@PEACH.EASE.LSOFT.COM Outlook Tips: http://www.outlook...

How do I convert a concatenated value into a know value
Hi all I am trying to get the results of a multiple input table, which get concatenated, read out as usable values eg. If the concatenated values are for example *llbbt* , I need this t be read as Simon, or *lbttd* must result in Fred etc... I will attact the spreadsheet. Thanks Colli Attachment filename: book3.xls Download attachment: http://www.excelforum.com/attachment.php?postid=54116 -- Message posted from http://www.ExcelForum.com You are probably better off by describing your problem, most regulars won't open files.. -- Regards, Peo Sjoblo...

MS Access 2007 code not running
I have created a brand new database in Access 2007 and linked some VB code to run on Form_Load. This code worked perfect with no problems the day I created it. Now today I opened the same form and it is not running the Form_Load code anymore (and yes it is still there, I did not delete it). I got frustrated so I copied and pasted the code to Form_Current and several On_Change events and set breakpoints at the beginning of all the events just to see if it was the Form_Load that was not triggering, but NO events are triggering my VB code. Any ideas? See this page: http://accessjunkie.com/fa...

unable to grant existing user access to TEST company
Set up test company using live company data; ran the script referenced in CustomerSource article ID#871973; can grant and remove user access in all other companies; ran grantsql 9.2; the dexsql log shows the user already has access probably because of using the other company data for the test; I can set up a new user and grant them access, existing users who already have access can view the company...but, I cannot figure out how to grant access to the TEST company to an existing user. The error popup reads "The user could not be added to one or more databases." Dynamics 9.0,...

Macro to change default setting on startup
I am in need of a macro that can change a default setting in excel and for it to run on startup The task is: Tools Options General Web Options Files uncheck Update links on save Below is the recording of the macro: With ActiveWorkbook.WebOptions ..RelyOnCSS = True ..OrganizeInFolder = True ..UseLongFileNames = True ..DownloadComponents = False ..RelyOnVML = False ..AllowPNG = False ..ScreenSize = msoScreenSize800x600 ..PixelsPerInch = 96 ..Encoding = msoEncodingWestern End With With Application.DefaultWebOptions ..SaveHiddenData = True ..LoadPictures = True ....

Value is BLANK
In a form i'm working on i've asked this question before and i'm unable to locate the replies, but in one cell I have a date to be enter and in the other cell it takes that date and add 5 days to the date to give me a due date. But if no date is enter then I want to to remain blank insted giving me a date. Say that the date is to be entered into A1, then enter this formula into the "other" cell: =IF(A1,A1+5,"") -- HTH, RD ============================================== Please keep all correspondence within the Group, so all may benefit! ==================...

Null value in form not trapped by beforeupdate event
I have a form in Access 2003 linked to a SQL Server 2005 table. When I clear the value in a textbox (bound field is varchar and is required), I want the before update event to run to tell the user the value cannot be null. When I press the tab button to move to the next field after clearing the texbox, the before update event is not triggering and instead I'm getting the following error: You tried to assign the Null value to a variable that is not a Variant data type. (Error 3162) How can I prevent nulls before and this error from triggering? Thanks! ...

Accessing another user's calendar OL2000/OL2003/Ex2000
Here's the situation: Running Exchange2000, v 6.0, sp4. Users are on XP/OL2003 or NT/OL2000. (we're in the process of upgrading all of the workstations to XP.) VIP user is on XP/OL2003. He can access his calendar just fine on his workstation. His secretary and other office admin type people are still on NT/OL2000. They have reviewer or editor rights to his calendar. They try to access his calendar by chosing File/Open/Other User's Folder... and put in his name and calendar. When they do this, the process hangs. In Task Manager, Outlook is "Running." End the Outloo...

SQL query / Formula for Reorder Point?
Is it possible to issue an SQL command(s) that would: 1. Set the Restock Level for all items to be equal to the current on-hand quantity for each item. 2. Set the Reorder point for all items to be equal to 1/3 of that items Restock Level. I'm currently doing this manually, or using a formula in excel when items are initially imported into the DB, but there are still several thousand that need to be retro-fitted like this... Thanx in advance! -=RFM=- UPDATE Item SET RestockLevel=(Quantity - QuantityCommitted) UPDATE Item SET ReorderPoint=ROUND(RestockLevel/3,0) - Evan Culver Ne...

copy values generated by conditional formula in one sheet to the other work sheet as values
Hi Everybody, I have data generated by conditional formulae in work sheet1 in columns A to J. If the condition is satisfied the cell will display a realnumber, if the condition doesn't satisfied the cell will display the text"FALSE". Now I wanted to copy the cells which have the real numbers in sheet1 to sheet2 as values(as we do with paste special and paste the values) Do we have any formula or other method to copy the cells in sheet1 to sheet2. can anybody helpme out in this issue. Thanks and Regards Ramana Select your range to copy edit|goto|special|c...