VB: dynaset and form onopen

tca_VB

Registered User.
Local time
Today, 17:51
Joined
Jul 12, 2007
Messages
24
I am debugging an access database that is pre-2000 and converted to 2002. There are several errors I'm trying to resolve, but the first couple relate to User-defined type not defined. (I have updated the reference to Microsoft DAO 3.6 and have tried adding Microsoft ActiveX Data Objects 2.8.)

Dim MDB As Database, Q As QueryDef, MSet As Dynaset, Chkform As Form
"In the above, the MSet as Dynaset, shows the error"

CR$ = Chr(13) & Chr(10) 'Carriage return and line feed
"In the above, Chr(13) also gave me an error"

Separate issue, but related to references. I'm having problems with the following code during a form OnOpen request. The OnOpen references =wu_CenterDoc(Form.Hwnd). Below is the related code:

'------------------------------------------------------------------------
' FUNCTION : wu_CenterDoc
'
' PURPOSE : Centers a Microsoft Access form.
'------------------------------------------------------------------------
Function wu_CenterDoc(hwnd%) As Integer
Dim r As WU_RECT, rDesk As WU_RECT
Dim dx As Integer, dy As Integer, dxDesk As Integer, dyDesk As Integer

DoCmd.Maximize

' Type WU_RECT.
'
Type WU_RECT
x1 As Integer
y1 As Integer
x2 As Integer
y2 As Integer
End Type

Thanks for any help. I'm a bit of a newbie to VB.
 
too complex or confusing

Is my question too complex or confusing/ambiguous? What could I do to write my question better to solicit some advice?
 
If you are using DAO or ADO, you need to fully qualify the variables -

For example when you declare your MDB As Database you will do
Dim MDB As DAO.Database

etcetera

As to your function, when you say you are having problems with it, can you be more specific about what problems?
 
Dao

Thanks for the suggestion. I added DAO in my dim statement as follows:
Dim MDB As DAO.Database, Q As DAO.QueryDef, MSet As DAO.Dynaset

It still gives me an error for MSet As DAO.Dynaset "User-defined type not defined"

I'm converting someone else's code, so I'm not exactly sure of my options. Does anyone have any suggestions about "dynaset"?
 
OnOpen

Also, more details on the OnOpen error. I get an "Overflow" error and the macro comes to a halt. In looking up the overflow error, it mentions adding the scroll bars. The form is not too big, nor does adding the scroll bars change anything.

I believe the error is due to the WU_RECT portion as I can't find any further references to how this was coded besides TYPE. Parts of the project are unviewable.

Any thoughts?


In the form properties, OnOpen references =wu_CenterDoc(Form.Hwnd). Below is the related code:

'------------------------------------------------------------------------
' FUNCTION : wu_CenterDoc
'
' PURPOSE : Centers a Microsoft Access form.
'------------------------------------------------------------------------
Function wu_CenterDoc(hwnd%) As Integer
Dim r As WU_RECT, rDesk As WU_RECT
Dim dx As Integer, dy As Integer, dxDesk As Integer, dyDesk As Integer

DoCmd.Maximize

' Type WU_RECT.
'
Type WU_RECT
x1 As Integer
y1 As Integer
x2 As Integer
y2 As Integer
End Type
 
Thanks for the suggestion. I added DAO in my dim statement as follows:
Dim MDB As DAO.Database, Q As DAO.QueryDef, MSet As DAO.Dynaset

It still gives me an error for MSet As DAO.Dynaset "User-defined type not defined"

I'm converting someone else's code, so I'm not exactly sure of my options. Does anyone have any suggestions about "dynaset"?

I'm pretty DynaSet isn't a object but rather a property of how you can access the recordset.

I think you want to set it thus:
Code:
MSet As DAO.Recordset

Then when you open the querydef, do thus:

Code:
Set MSet = Q.OpenRecordset(dbOpenDynaset)

This is off the top of my head, so not positively sure about if we need the (dbOpenDynaset). If you get error, search a bit more here; I know I've answered similar question a while back.
 
Also, more details on the OnOpen error. I get an "Overflow" error and the macro comes to a halt. In looking up the overflow error, it mentions adding the scroll bars. The form is not too big, nor does adding the scroll bars change anything.

I believe the error is due to the WU_RECT portion as I can't find any further references to how this was coded besides TYPE. Parts of the project are unviewable.

Any thoughts?


In the form properties, OnOpen references =wu_CenterDoc(Form.Hwnd). Below is the related code:

'------------------------------------------------------------------------
' FUNCTION : wu_CenterDoc
'
' PURPOSE : Centers a Microsoft Access form.
'------------------------------------------------------------------------
Function wu_CenterDoc(hwnd%) As Integer
Dim r As WU_RECT, rDesk As WU_RECT
Dim dx As Integer, dy As Integer, dxDesk As Integer, dyDesk As Integer

DoCmd.Maximize

' Type WU_RECT.
'
Type WU_RECT
x1 As Integer
y1 As Integer
x2 As Integer
y2 As Integer
End Type

It's much easier to write code in [code][/code] tags.

Anyway, I don't think we're seeing the complete function. For one thing, there's no "End Function" at the bottom of line. Also, there seems to be nothing going on besides merely declaring a custom defined data type and setting integer. There's nothing that would actually do anything to center the form, beyond maximizing the form. I think some lines is definitely missing here... Maybe look in your pre-converted database and see if there's more there?
 
Also, Type declarations need to be in the General Declarations section, not within a function or sub.
 
onopen form

I'm guessing you are correct in that it is only maximizing the form now. Below is the whole function. Most of the center actions are commented out.

The Type WU_RECT / End Type is at the top in the declarations section. I just added it to the bottom to send in the thread. My guess is that the TYPE library is only local and I don't have it on my machine when I received the database and that's why the error. With that assumption, could I just remove it and just have a maximize command onopen? Thoughts?

Thank you for the suggestions!

'------------------------------------------------------------------------
' FUNCTION : wu_CenterDoc
'
' PURPOSE : Centers a Microsoft Access form.
'------------------------------------------------------------------------
Function wu_CenterDoc(hwnd%) As Integer
Dim r As WU_RECT, rDesk As WU_RECT
Dim dx As Integer, dy As Integer, dxDesk As Integer, dyDesk As Integer

DoCmd.Maximize

' If (hwnd% = 0) Then hwnd = wu_GetCurrentDoc(True)
'hwndDesk% = wu_GetParent(hwnd%)
'stClass$ = wu_StWindowClass(hwnd%)
'
'' Special case for forms: Move them to 0,0 and do a SizeToFitForm
'
'If (stClass$ = WU_WC_ACCESSFRM) Then
'DoCmd.MoveSize 0, 0
'On Error Resume Next
'DoCmd.DoMenuItem A_FORMBAR, 4, 5
'On Error GoTo 0
'End If
'
'' If this is a popup, use the WindowRect of the desktop. Otherwise,
' use the client rect.

'f% = wu_GetWindowRect(hwnd%, r)
'If (stClass$ = WU_WC_ACCESSFRMPOPUP) Then
'f% = wu_GetWindowRect(hwndDesk%, rDesk)
'Else
'f% = wu_GetClientRect(hwndDesk%, rDesk)
'End If
'dx% = r.x2 - r.x1
'dy% = r.y2 - r.y1
'dxDesk% = rDesk.x2 - rDesk.x1
'dyDesk% = rDesk.y2 - rDesk.y1
'If (wu_StWindowClass(hwnd%) = WU_WC_ACCESSFRMPOPUP) Then
'f% = wu_MoveWindow(hwnd%, rDesk.x1 + (dxDesk% - dx%) / 2, rDesk.y1 + (dyDesk% - dy%) / 2, dx%, dy%, True)
'Else
'f% = wu_MoveWindow(hwnd%, (dxDesk% - dx%) / 2, (dyDesk% - dy%) / 2, dx%, dy%, True)
'End If
'wu_CenterDoc = f%
End Function
 
Now, I've not worked with older versions of Access, but I realized that the function may be now unnecessary for Access 2003 (Maybe 2000 and 2002, too?) as you can auto-center the form in its properties windows. It's in "Format" tab, somewhere in middle of the list.
 
My guess is that the TYPE library is only local and I don't have it on my machine when I received the database and that's why the error.
Actually the type declaration shows that the type is being created on your computer and not within a Type Library (.tlb). So, it actually IS on your computer but there may be other things happening. I don't have time to test to see, but I thought you should at least get feedback on that statement.
 
CR$ = Chr(13) & Chr(10) 'Carriage return and line feed
"In the above, Chr(13) also gave me an error"

Use Visual Basic's constant: vbCrLf

EG.
Code:
...
MsgBox "This is an example of" & [COLOR="Red"]vbCrLf[/COLOR] & _
           "Visual Basic's cariage return" & [COLOR="red"]vbCrLf[/COLOR] & _
           "line feed constant.", vbInformation, _
           "vbCrLf Example"
...

And assuming your data is in the database your currently coding in

Code:
Dim rs As DAO.Recordset
Dim sql As String

sql = "SELECT * " & _
       "FROM MyTable;"
Set rs = CurrentDb.OpenRecordset(sql, dbOpenDynaset)
 

Users who are viewing this thread

Back
Top Bottom