Access 2016 - api functions (1 Viewer)

lana

Registered User.
Local time
Today, 17:29
Joined
Feb 10, 2010
Messages
92
Hello there,


I have used Windows API functions in access 2016 on Windows 10. I used the correct format for 64bit.

It works fine in one computer but gives me "Type mismatch error" on another computer with Windows 10 and also Access 2016?


Any help would be appreciated.


Thanks a lot.
 

Ranman256

Well-known member
Local time
Today, 08:59
Joined
Apr 9, 2015
Messages
4,339
did you try with the PTRSAFE ?

Declare PtrSafe Function MyMathFunc Lib "User32" (ByVal N As LongLong) As Long
 

lana

Registered User.
Local time
Today, 17:29
Joined
Feb 10, 2010
Messages
92
Yes.
It works fine without error in one computer (Win10, Access 2016).



On another computer with Win10 and Access 2016 gives me this "Type mismatch error"???
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:59
Joined
Feb 28, 2001
Messages
27,001
Is the "bitness" the same on the working and non-working systems? Not only Windows but also Office.

Another factor to consider is that your references are a function of the registry, which is not the same from computer A to computer B. So see whether the references between the two systems are the same. And I'm not necessarily talking about a reference to the WinAPI module itself, which is often late-bound anyway. I have seen a few cases where I saw the type mismatch on some call, and it was caused by a missing reference to something else entirely unrelated to the failing call. Can't tell you why, but I've seen it.
 

Dreamweaver

Well-known member
Local time
Today, 12:59
Joined
Nov 28, 2005
Messages
2,466
I would use longptr instead of long long as one could be running office 32 bit
 

lana

Registered User.
Local time
Today, 17:29
Joined
Feb 10, 2010
Messages
92
Hello there,


Many thanks for the replies.


I changed all the LongPtr to LongLong and error disappeared BUT...


At the beginning of my code I used these functions :


hDC = apiGetDC(hWndAccessApp)
XPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSX)
YPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSY)
lngRetVal = apiReleaseDC(hWndAccessApp, hDC)



The strange thing is : the returned numbers are

hDC =1593903413^
XPIXELSPERINCH = 96^
YPIXELSPERINCH = 96^
lngRetVal= 1^



I don't understand why ^ appears at the end of the numbers???
because of this the rest of my code does not work.


Any ideas??
Really appreciate any help.
Cheers
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:59
Joined
Feb 28, 2001
Messages
27,001
Where do you see those answers with carets? They are indicative of the data type of the variable. I suspect that you are getting LongLong returns from the functions you called, but I've lost track of the page that explains the various formatting symbols.

In any case, if you wanted them in another format, I think you can just use a conversion functions on everything that SHOULD just be an integer. However, your hDC might not be "just" an integer so I would be careful with it.
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 12:59
Joined
Jan 14, 2017
Messages
18,186
As has already been mentioned, using LongLong is unhelpful as your code will then not run in 32-bit Access

LongPtr has been designed so it will work in both 'bitnesses' for Access 2010 and later
 

lana

Registered User.
Local time
Today, 17:29
Joined
Feb 10, 2010
Messages
92
Hello,

Thanks for the replies.

My code works in one computer with Win10, access 2016 but I have this problem in another computer.

My code is calculating the co-ordinates of a text box and moves a form there like a DatePicker.

Dim hDC As LongLong, lngRetVal As LongLong

hDC = apiGetDC(hWndAccessApp)
XPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSX)
YPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSY)
lngRetVal = apiReleaseDC(hWndAccessApp, hDC)

'''''''''''''''''''''''''''''''''''''''''''''''''''

Dim hWndTextBox As LongLong, rectTextBox As RECT_Type
Dim hWndMDIClient As LongLong, rectMDIClient As RECT_Type

Forms(aa).Controls(bb).SetFocus
hWndTextBox = apiGetFocus()
lngRetVal = apiGetWindowRect(hWndTextBox, rectTextBox)
hWndMDIClient = apiFindWindowEx(hWndAccessApp, 0, "MDIClient", vbNullString)
lngRetVal = apiGetWindowRect(hWndMDIClient, rectMDIClient)

' Make metrics relative to the MDIClient window
With rectTextBox
.Bottom = .Bottom - rectMDIClient.Top - apiGetSystemMetrics(SM_CYBORDER)
.Left = .Left - rectMDIClient.Left - apiGetSystemMetrics(SM_CXBORDER)
.Right = .Right - rectMDIClient.Left - apiGetSystemMetrics(SM_CXBORDER)
.Top = .Top - rectMDIClient.Top - apiGetSystemMetrics(SM_CYBORDER)
End With

' Convert the measurements from pixels to twips.
With rectTextBox
.Bottom = .Bottom * (TWIPSPERINCH / XPIXELSPERINCH)
.Left = .Left * (TWIPSPERINCH / XPIXELSPERINCH)
.Right = .Right * (TWIPSPERINCH / XPIXELSPERINCH)
.Top = .Top * (TWIPSPERINCH / XPIXELSPERINCH)
End With

Me.Move Left:=rectTextBox.Left, Top:=rectTextBox.Bottom




hWndAccessApp returns 66578 on the computer which works and returns 328548 on the other.

?????
 

isladogs

MVP / VIP
Local time
Today, 12:59
Joined
Jan 14, 2017
Messages
18,186

lana

Registered User.
Local time
Today, 17:29
Joined
Feb 10, 2010
Messages
92
Thanks.


I can not use simple move method.


If a text box (anywhere on the form) is double clicked, a specific form must be opened exactly below that text box.
The co-ordinates of the text box relative to the screen is needed (not relative to the form).


My code works fine for access 2003 and also on 2016 in one of my laptops. The new one with access 2016 gives this problem.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:59
Joined
Feb 28, 2001
Messages
27,001
hWndAccessApp returns 66578 on the computer which works and returns 328548 on the other.

Yes. If those are "window handles" (as the nomenclature seems to indicate) then they are actually internal addresses of a structure. The "handle" is like a pointer, and you can run the same code twice on the same computer, time-shifted a little, and STILL get different handles. Whenever you see "hWnd" as the prefix, that is a window handle and you NEVER modify it. Nor can you make sense out if it. It's just a pointer to something for which the location is not predictable. You CANNOT assign ANY significance to the fact that they differ.
 

isladogs

MVP / VIP
Local time
Today, 12:59
Joined
Jan 14, 2017
Messages
18,186
Slightly trickier BUT you still don't need to use an API.
The attached example has 2 forms: Form 1 & Form2
Form1 - has 2 textboxes and an orange rectangle
Double click either textbox - Form2 will open/move directly below that textbox
The orange box will also move - directly below the other textbox

Try moving Form1 on the screen or its controls within the form.
It should still work

Hopefully the code is understandable - its only a few lines
Ask if its not clear

For info, I use this idea for a custom zoom box where there is too much test to fit the textbox.
Double click a control and the zoombox form opens directly below it!
 

Attachments

  • MoveForm&Control.accdb
    452 KB · Views: 288

lana

Registered User.
Local time
Today, 17:29
Joined
Feb 10, 2010
Messages
92
Thanks so much. I will try your suggestion. It's appears to be much simpler. Thanks again. Cheers
 

isladogs

MVP / VIP
Local time
Today, 12:59
Joined
Jan 14, 2017
Messages
18,186
I've nothing against the use of APIs and use them where they provide the best or at times only solution.

My approach here is definitely much simpler and more importantly I believe it will work on any workstation.

Good luck.
 
Last edited:

lana

Registered User.
Local time
Today, 17:29
Joined
Feb 10, 2010
Messages
92
Thanks so much.


I tried your suggestion and it works fine for a text box on a form but when I use it on a sub form ....


There is a sub form on the main form. There is a field in the sub form which I need to put the code on it's double click event. When I do that the co-ordinates of the opened form is the co-ordinates of the text box on the sub form in its form view not on its datasheet view.


Any ideas?
 

isladogs

MVP / VIP
Local time
Today, 12:59
Joined
Jan 14, 2017
Messages
18,186
I'm only half awake.
So I'm sure I'm understanding correctly, please can you post a screenshot.
 

lana

Registered User.
Local time
Today, 17:29
Joined
Feb 10, 2010
Messages
92
Many thanks.
I attached a pdf file.
I hope it's clear.


Thanks again
 

Attachments

  • pop up form position-compressed.pdf
    71.1 KB · Views: 206

isladogs

MVP / VIP
Local time
Today, 12:59
Joined
Jan 14, 2017
Messages
18,186
Hi lana

AFAIK it can't be done with a datasheet.
As you said, the popup form moves to the design view control position

That's because the datasheet controls are actually where they are located in design view but 'trickery' is used to layout the form controls as they appear on screen

BUT the good news is it can be done with a continuous form ... which can be made to look/behave almost like a datasheet anyway.

New version attached with additional forms.
a) Form1 - single form as in previous version
b) Form 2 - continuous
c) Form 3 - with Form 2 as continuous subform

The other form is now called frmZoom and shows how it can be used to display the contents of the clicked textbox

Hope that helps
 

Attachments

  • MoveForm&Control_v2.zip
    46.8 KB · Views: 226

isladogs

MVP / VIP
Local time
Today, 12:59
Joined
Jan 14, 2017
Messages
18,186
Further update to version 3. Improvements include:
1. The previous version was intended for use with overlapping windows only
I've now modified the code & forms so it now works using tabbed documents as well
2. The previous version placed the zoom box with reference to the autonumber ID field.
Of course if the numbers aren't continuous due to deleted records that will 'go wrong'
This version instead uses a Serialize function to get the rank order or 'record number' for the selected record
3. I've also added code to handle nulls and blank textboxes



It seems to work well now from my testing. Let me know what you think
 

Attachments

  • MoveForm&Control_v3.zip
    52.9 KB · Views: 267
  • Capture.PNG
    Capture.PNG
    23.2 KB · Views: 667
Last edited:

Users who are viewing this thread

Top Bottom