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 / Modules / DAO / VBA / October 2007

Tip: Looking for answers? Try searching our database.

User Defining Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan @BCBS - 05 Oct 2007 22:01 GMT
I'm trying to copy data to a new table.

My command botton code grabs the data, creates a new record in the
destination table and dumps it in. It reads a public function called
"GetNewID" to create a new record.

I'm having a problem defining a place for the data.
Here is both the public function and the command button code:

Public Function GetNewID(tblName As String) As Long
   Dim db As Database
   Dim rs As Recordset
   
   Set db = CurrentDb
     Set rs = db.OpenRecordset(tblName)
     ' Set rs = HoldData
   
   If rs.RecordCount > 0 Then
       rs.MoveLast
       GetNewID = rs.Fields(0) + 1
   Else
       GetNewID = 0
/////////////

Private Sub ThankYou_Click()
   
  Dim lCriteria As String
   Dim lICCNNO As String

   lICCNNO = Me!ICNNo
 
   Dim lID As Long
    lID = GetNewID("tblLetterVals")
           lCriteria = "INSERT INTO tblLetterVals (ID, ICNNo, ProvNo)"
           
           lCriteria = lCriteria & "SELECT " & lID & " AS ID,
tblQualityData.ICNNo, tblQualityData.ProvNo "
                                   
           lCriteria = lCriteria & "FROM tblQualityData "
           lCriteria = lCriteria & "WHERE (((tblQualityData.ICNNo)=" & """"
& lICCNNO & """" & "));"
           DoCmd.RunSQL lCriteria
   'Debug.Print lCriteria
   
               
    DoCmd.SetWarnings True
    DoCmd.GoToRecord , , acNewRec
Tom van Stiphout - 06 Oct 2007 06:45 GMT
You're using confusing language, at least to me.

GetNewID does not create a new record. It merely returns the next ID
value to use.

"a place for the data"?  According to your Insert statement that would
be tblLetterVals.

What exactly is the problem?  Are you getting any error messages?

-Tom.

>I'm trying to copy data to a new table.
>
[quoted text clipped - 44 lines]
>     DoCmd.GoToRecord , , acNewRec
>              
Dan @BCBS - 07 Oct 2007 19:29 GMT
Yes
Run-Time error - 13 Type mismatch
At this point: Set rs = db.OpenRecordset(tblName)

When I run this I am expecting to copy the values to tblLetterVals.

Any ideas?

> You're using confusing language, at least to me.
>
[quoted text clipped - 56 lines]
> >     DoCmd.GoToRecord , , acNewRec
> >              
 
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.