Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / April 2006

Tip: Looking for answers? Try searching our database.

RunTime Error 13......Mismatch

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
orsonros@hotmail.com - 08 Apr 2006 23:59 GMT
Hi!

I have written the following code to create a RECORDSET . Whenever I
load the program it gives me a mismatch error. I like to know why this
error occurs, and what remedial action is to be taken. Are any setting
to be done?

The database is Trad1.mdb & table  tblMain

Help needed

Thanks

ORS

Option Compare Database
Option Explicit
Dim MainWS As Workspace, MainDb As Database
Dim rstMain As Recordset

Private Sub Form_Load()
On Error GoTo Error_Handler

Set MainWS = DBEngine.Workspaces(0)
Set MainDb = DBEngine.OpenDatabase("c:\Trad1.mdb")

' This will create a table-type Recordset.
Set rstMain = MainDb.OpenRecordset("tblMain", dbOpenTable)

rstMain.Index = "TID"

   rstMain.MoveLast
   ShowData

Exit_Here:
 Exit Sub

Error_Handler:
MsgBox Err.Number & ":" & Err.Description
Resume Exit_Here

End Sub

'
Allen Browne - 09 Apr 2006 06:53 GMT
Both the DAO and ADO libraries have a Recordset object. The "type mismatch"
error suggests you are getting the wrong one.

Try specifying the type you want:
   Dim rstMain As DAO.Recordset

More info about libraries, and which ones you need for each version of
Access:
   http://allenbrowne.com/ser-38.html

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> I have written the following code to create a RECORDSET . Whenever I
> load the program it gives me a mismatch error. I like to know why this
[quoted text clipped - 36 lines]
>
> End Sub
orsonros@hotmail.com - 10 Apr 2006 15:36 GMT
Thanks Allen,

The "Type mismatch error" has gone, but now on click event of cmdAdd it
does not take me to a new record! why?

Ors
Allen Browne - 10 Apr 2006 16:09 GMT
That might depend on what is in the code for the button.

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Thanks Allen,
>
> The "Type mismatch error" has gone, but now on click event of cmdAdd it
> does not take me to a new record! why?
orsonros@hotmail.com - 11 Apr 2006 07:06 GMT
Option Compare Database
Option Explicit
Dim MainWS As Workspace, MainDb As Database
Dim rstMain As DAO.Recordset
'Declare this logical variable
Dim bAddNew As Boolean

Private Sub cmdAdd_Click()

   bAddNew = True

    rstMain.MoveLast
   rstMain.AddNew

End Sub

This the code for adding new record. It does not take me to a new
record.

Ors
TC - 11 Apr 2006 07:29 GMT
1. You do not need to do MoveLast, before you do Addnew.

2. Doing an AddNew is pointless, unless you subsequently put some
values into the fields of the new recordset entry, and then use the
.Update method to save the new record into the database. Otherwise, the
unsaved new record is discarded automatically.

3. None of the above will have any affect on the records *displayed in
your form*.

4. Why are you doing this anway? Access *automatcally* lets you add,
edit & delete records, via a form, without writing any code at all.

HTH,
TC (MVP Access)
http://tc2.atspace.com
orsonros@hotmail.com - 13 Apr 2006 18:36 GMT
Hi! TC,

You asked why am I doing it this way.

Well I had written it the same way for a Visual Basic program and it
did well, so I thought maybe it should work in Access as well.

Am I right or do the access coding have differences?

I don't know!!!

Ors
TC - 15 Apr 2006 13:12 GMT
Access has the concept of "bound forms". You can create forms that let
the user find, view, add, edit, and delete records, *without any
programming*. I'm no VB expert, but I don't think that VB has bound
forms. So clearly, you approach the job quite differently, when using
Access, compared to VB.

In general, there's no guarantee that a particular programming method
that works with VB, will work correctly - or at all - with Access. In
particular, the code that you have shown so far - taken exactly as you
have written it - will not work in Access, *or VB*.

I suggest that you forget that code, and research the use of "bound
forms" in Access. In particular, check ut the form-level RecordSource
property, and the control-level ControlSource property, in F1 Help.

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.