PC Review


Reply
Thread Tools Rate Thread

Dim rs As DAO.Recordset Error

 
 
Bateman28
Guest
Posts: n/a
 
      12th Mar 2010
Hi

I Am trying to create an import routine from an on-click demand function
button within a form. I have done this many times before from using a button
function within a form, but for some reason when trying to create the import
button function from the on-click demand this time around I seem to be
failing at the first hurdle and I don't understand why. When I try to run the
button function I get the following error message "User - Defined type
not Defined"! I have experience with VB code but it’s not extensive. I have
posted the beginning of my code to see if anyone can help me out....If you
could it would be greatly appreciated Thanks

Private Sub ImportMonthlyMBD_Click()
On Error GoTo Err_ImportMonthlyMBD_Click

Dim sSQL As String 'The SQL String To Be Executed
Dim nResp As Integer

Dim rs As DAO.Recordset 'The DAO recordset
Dim rs1 As DAO.Recordset 'The DAO recordset
Dim rs2 As DAO.Recordset 'The DAO recordset

Set myDB = CurrentDb 'Use this database
Set rs = Nothing 'Tidy up the recordset
Set rs1 = Nothing 'Tidy up the recordset
Set rs2 = Nothing 'Tidy up the recordset

sSQL = ""

dDate = Date
sDate = Format(dDate, "dd-mmm-yyyy")

'Import all Data from the Alldata File

nResp = MsgBox("Do you wish to Import the Monthly Data?", vbYesNo)

If nResp = vbYes Then

'Clear out the old data from the DailyTempTable First
DoCmd.SetWarnings False
sSQL = "delete * from DailyTempTable;"
DoCmd.RunSQL (sSQL)

sFileName = Me![MBDMonthlyDatePathname]

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9,
"DailyTempTable", sFileName, True

'First of all - Put all the records with a blank Title & blank First
Name fields into the DailyJobsExceptions Table

sSQL = "insert into DailyJobsExceptions select * from DailyTempTable
where isnull(DailyTempTable.[Title])And where isnull(DailyTempTable.[First
Name]);"
DoCmd.RunSQL (sSQL)

sSQL = "delete from DailyTempTable where isnull(DailyTempTable.[Title])
And where isnull(DailyTempTable.[First Name]);"
DoCmd.RunSQL (sSQL)

sSQLnextval = "select max(MainTable.RefNo) from MainTable;"
Set rs = CurrentDb.OpenRecordset(sSQLnextval)

If Not rs.EOF Then
nNextRefNo = rs.Fields(0) + 1
Else
nNextRefNo = 1
End If
Set rs = Nothing 'Tidy up the recordset


 
Reply With Quote
 
 
 
 
Jeanette Cunningham
Guest
Posts: n/a
 
      12th Mar 2010
Looking at the first few lines of code you posted


Private Sub ImportMonthlyMBD_Click()
On Error GoTo Err_ImportMonthlyMBD_Click

Dim sSQL As String 'The SQL String To Be Executed
Dim nResp As Integer

Dim rs As DAO.Recordset 'The DAO recordset
Dim rs1 As DAO.Recordset 'The DAO recordset
Dim rs2 As DAO.Recordset 'The DAO recordset

Set myDB = CurrentDb 'Use this database
Set rs = Nothing 'Tidy up the recordset
Set rs1 = Nothing 'Tidy up the recordset
Set rs2 = Nothing 'Tidy up the recordset

sSQL = ""



these 3 lines

Set rs = Nothing 'Tidy up the recordset
Set rs1 = Nothing 'Tidy up the recordset
Set rs2 = Nothing 'Tidy up the recordset

would be put at the exit handler for the code.

So, first step is to comment out those 3 lines of code under set myCB =
CurrentDb (put an apostrophe in front of each line).
Next see if the code compiles

The code you posted only uses rs, but does not use rs1 and rs2.
So at the exit handler, use

On Error Resume Next
Set rs = Nothing

between the 1st line of the exit handler and the exit sub line.



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia



"Bateman28" <(E-Mail Removed)> wrote in message
news:8BF3FAC0-2ED3-4A0B-BD99-(E-Mail Removed)...
> Hi
>
> I Am trying to create an import routine from an on-click demand function
> button within a form. I have done this many times before from using a
> button
> function within a form, but for some reason when trying to create the
> import
> button function from the on-click demand this time around I seem to be
> failing at the first hurdle and I don't understand why. When I try to run
> the
> button function I get the following error message "User - Defined
> type
> not Defined"! I have experience with VB code but it's not extensive. I
> have
> posted the beginning of my code to see if anyone can help me out....If you
> could it would be greatly appreciated Thanks
>
> Private Sub ImportMonthlyMBD_Click()
> On Error GoTo Err_ImportMonthlyMBD_Click
>
> Dim sSQL As String 'The SQL String To Be Executed
> Dim nResp As Integer
>
> Dim rs As DAO.Recordset 'The DAO recordset
> Dim rs1 As DAO.Recordset 'The DAO recordset
> Dim rs2 As DAO.Recordset 'The DAO recordset
>
> Set myDB = CurrentDb 'Use this database
> Set rs = Nothing 'Tidy up the recordset
> Set rs1 = Nothing 'Tidy up the recordset
> Set rs2 = Nothing 'Tidy up the recordset
>
> sSQL = ""
>
> dDate = Date
> sDate = Format(dDate, "dd-mmm-yyyy")
>
> 'Import all Data from the Alldata File
>
> nResp = MsgBox("Do you wish to Import the Monthly Data?", vbYesNo)
>
> If nResp = vbYes Then
>
> 'Clear out the old data from the DailyTempTable First
> DoCmd.SetWarnings False
> sSQL = "delete * from DailyTempTable;"
> DoCmd.RunSQL (sSQL)
>
> sFileName = Me![MBDMonthlyDatePathname]
>
> DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9,
> "DailyTempTable", sFileName, True
>
> 'First of all - Put all the records with a blank Title & blank First
> Name fields into the DailyJobsExceptions Table
>
> sSQL = "insert into DailyJobsExceptions select * from DailyTempTable
> where isnull(DailyTempTable.[Title])And where isnull(DailyTempTable.[First
> Name]);"
> DoCmd.RunSQL (sSQL)
>
> sSQL = "delete from DailyTempTable where isnull(DailyTempTable.[Title])
> And where isnull(DailyTempTable.[First Name]);"
> DoCmd.RunSQL (sSQL)
>
> sSQLnextval = "select max(MainTable.RefNo) from MainTable;"
> Set rs = CurrentDb.OpenRecordset(sSQLnextval)
>
> If Not rs.EOF Then
> nNextRefNo = rs.Fields(0) + 1
> Else
> nNextRefNo = 1
> End If
> Set rs = Nothing 'Tidy up the recordset
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Recordset error Irene Microsoft Access Getting Started 1 17th May 2008 05:40 AM
Recordset error =?Utf-8?B?aXNiam9ybmVu?= Microsoft Access VBA Modules 1 22nd Mar 2005 02:11 AM
DAO error getting recordset Spammastergrand Microsoft Access Queries 2 19th Dec 2003 02:50 AM
Recordset error Alexis Microsoft Access VBA Modules 1 10th Dec 2003 08:15 PM
ADO Recordset error Robert Microsoft Access VBA Modules 2 11th Nov 2003 06:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:10 PM.