Change GotoRecord Method To RecordsetClone - ms-access

I need to change the GotoRecord in This Code To RecordsetClone Method Because i Have a problem With GotoRecord which ruining everything for me
Dim sql As DAO.Recordset
Set sql = CurrentDb.OpenRecordset("TblPoMaterials", dbOpenDynaset)
DoCmd.SetWarnings False
DoCmd.GoToRecord , , acFirst ' THE PROBLEM IS HERE
For m = 1 To T8
With sql
.AddNew
!PONumber = T7
!MaterialCode = Code1
!MaterialName = T1
!ProductionDate = T6
!Shift = "none"
!cons = T2
!AdditionPercent = Text324
!MaterialType = Text300
!OrderQty = T3
.Update
End With
DoCmd.GoToRecord , , acNext
Next m
MsgBox "Done", vbInformation, "Saved successfully"
The Form Is Unbound Continuous Form with this code
SELECT Bom.productcode, Bom.code, Bom.Item, Bom.cons, Bom.BomNumber, [Item Names].Type, Bom.Remarks FROM [Item Names] INNER JOIN Bom ON [Item Names].code = Bom.code WHERE (((Bom.productcode)=Forms!FrmNewPo!t0) And ((Bom.BomNumber)=Forms!FrmNewPo!Bom));

Related

Changing form from edit mode to new mode run time error 2105

I am trying to create a form that will do a search of first name and last name. If the record is found then edit the found record. If the record is not found then create a new record.
The search for an existing record works great. When I can't find a record and I try to switch the form mode to New and create a new record I am currently getting the run time error 2105 You can't go to the specified record. I have been working on this for about a week to no avail. I am hoping I can get some help.
Private Sub cmdSearch_Click()
Dim strFixID As String
Dim lMaxCustNum As Long
Dim lMaxId As Long
Set frmCurrentForm = Screen.ActiveForm
Stop
DoCmd.SetWarnings False
strTable = "tblMarketBulletinNew"
Me.FilterOn = False
Me.Filter = "[FirstName1] like '" & Me.txtSearchFirstName & "*' AND [LastName1] like '" &
Me.txtSearchlastName & "*'"
Me.FilterOn = True
If Me.Recordset.recordCount > 0 Then
'If record exists
DoCmd.GoToRecord , , acFirst
'Change Default value for Action for existing record
Me.txtOrigSignUpDate.Locked = True
Me.txtAction.Locked = False
Me.txtExpirationDate.Locked = True
Else
'No record exists so create new record
Me.FilterOn = False
Me.DataEntry = True
Me.AllowEdits = True
Me.AllowAdditions = True
Me.AllowDeletions = True
'To prevent error the changed you were requested were unsucessful
lMaxId = DMax("ID", strTable) + 1
strFixID = "ALTER TABLE " & strTable & " ALTER COLUMN ID COUNTER(" & lMaxId & ",1);"
Debug.Print strFixID
'DoCmd.RunSQL strFixID
lMaxCustNum = DMax("NewCustNum", strTable) + 1
Me.Recordset.AddNew
Me.txtCustNumber = lMaxCustNum
Me.SetFocus
DoCmd.GoToRecord , , acNewRec
Me.txtAction.DefaultValue = "New"
Me.txtAction.Locked = True
Me.lblRenSignupDate.Visible = False
Me.txtrenSignupDate.Visible = False
Me.txtStatus.DefaultValue = "Active"
Me.txtExpirationDate.Locked = True
'Add First and Last name already entered
Me.txtFirstName1 = txtSearchFirstName
Me.txtLastName1 = txtSearchlastName
Me.txtOrigSignUpDate = Date
End If
DoCmd.SetWarnings True
End Sub
Either use the form to add the record:
lMaxCustNum = DMax("NewCustNum", strTable) + 1
DoCmd.GoToRecord , , acNewRec
Me.txtCustNumber = lMaxCustNum
'...
Me.txtFirstName1 = txtSearchFirstName
Me.txtLastName1 = txtSearchlastName
Me.txtOrigSignUpDate = Date
' Save record.
Me.Dirty = False
or use the RecordsetClone:
Dim Records As DAO.Recordset
Set Records = Me.RecordsetClone
Records.AddNew
Records!CustNumber.Value = lMaxCustNum
' ...
Records!FirstName1.Value = Me!txtSearchFirstName.Value
Records!LastName1.Value = Me!txtSearchlastName.Value
Records!OrigSignUpDate.Value = Date
Records.Update
Records.Close

the command or action 'GoToRecord' isn't available now Accde Database

I have a problem with a continuous form producing this error the command or action 'GoToRecord' isn't available now, This is the form source:
SELECT Bom.productcode, Bom.code, Bom.Item, Bom.cons, Bom.BomNumber, [Item Names].Type, Bom.Remarks FROM [Item Names] INNER JOIN Bom ON [Item Names].code = Bom.code WHERE (((Bom.productcode)=Forms!FrmNewPo!t0) And ((Bom.BomNumber)=Forms!FrmNewPo!Bom));
This Error Happens when I press a command button with this code on click event:
Private Sub Command204_Click()
DoCmd.OpenForm "Robot"
DoCmd.GoToRecord , , acNewRec
Forms![Robot]![PONumber] = Me.T7
Forms![Robot]![productcode] = Me.t0
Forms![Robot]![OrderQty] = Me.T3
Forms![Robot]![zdate] = Me.T6
Forms![Robot]![Mold] = Me.Mold
Forms![Robot]![Machine] = Me.Machine
Forms![Robot]![Status] = Me.Status
Forms![Robot]![ProductBomNum] = Me.Bom
DoCmd.Close
Dim sql As DAO.Recordset
Set sql = CurrentDb.OpenRecordset("TblPoMaterials", dbOpenDynaset)
DoCmd.SetWarnings False
DoCmd.GoToRecord , , acFirst ' I THINK THE PROBLEM IS HERE
For m = 1 To T8
With sql
.AddNew
!PONumber = T7
!MaterialCode = Code1
!MaterialName = T1
!ProductionDate = T6
!Shift = "none"
!cons = T2
!AdditionPercent = Text324
!MaterialType = Text300
!OrderQty = T3
.Update
End With
DoCmd.GoToRecord , , acNext
Next m
MsgBox "Done", vbInformation, "Saved successfully"
DoCmd.SetWarnings True
t0 = ""
T6 = ""
T7 = ""
T3 = ""
T10 = ""
T10 = ""
Status = ""
BomCombo = ""
Me.ComboMachine = ""
Me.ComboMold = ""
Mold = ""
Machine = ""
T216 = ""
Me.Requery
The robot form appends the header of the form to a table, the SQL appends the detail part to some other table. When the error happened I found the header in the first table but the detail part isn't found in the other table so I suspected the line in the code is causing this problem but I don't know why!
I tried another approach as following:
Private Sub Command204_Click()
DoCmd.OpenForm "Robot"
DoCmd.GoToRecord , , acNewRec
Forms![Robot]![PONumber] = Me.T7
Forms![Robot]![productcode] = Me.t0
Forms![Robot]![OrderQty] = Me.T3
Forms![Robot]![zdate] = Me.T6
Forms![Robot]![Mold] = Me.Mold
Forms![Robot]![Machine] = Me.Machine
Forms![Robot]![Status] = Me.Status
Forms![Robot]![ProductBomNum] = Me.Bom
DoCmd.Close
DoCmd.SetWarnings False
DoCmd.GoToRecord , , acFirst
For m = 1 To T8
DoCmd.OpenQuery "QryAppendMat2"
DoCmd.GoToRecord , , acNext
Next m
MsgBox "Done", vbInformation, "Saved successfully"
DoCmd.SetWarnings True
t0 = ""
T6 = ""
T7 = ""
T3 = ""
'T5 = ""
T10 = ""
T10 = ""
Status = ""
BomCombo = ""
Me.ComboMachine = ""
Me.ComboMold = ""
Mold = ""
Machine = ""
T216 = ""
Me.Requery
The QryAppendMat2 is an append query which does the same job as the previous SQL Statement the code as following:
INSERT INTO TblPoMaterials ( PONumber, MaterialCode, MaterialName, Cons, MaterialType, ProductionDate, Shift, AdditionPercent, OrderQty )
SELECT [Forms]![FrmNewPo]![T7] AS Expr1, [Forms]![FrmNewPo]![Code1] AS Expr2, [Forms]![FrmNewPo]![T1] AS Expr3, [Forms]![FrmNewPo]![T2] AS Expr6, [Forms]![FrmNewPo]![Text300] AS Expr8, [Forms]![FrmNewPo]![T6] AS Expr4, "none" AS Expr5, [Forms]![FrmNewPo]![Text324] AS Expr7, [Forms]![FrmNewPo]![T3] AS Expr9;
But the same problem happened And I don't know why.
I have some Remarks :
-The problem happens in the accde with linked tables not with the accdb database.
-The problem happens one time of five , Meaning it works fine sometimes and other times just don't.
-The same conditions exactly could proceed normally after the problem happens when I try it again.
I need some help guys and so sorry for long question, but I tried to cover all possible questions.
Sounds like should be using form/subform arrangment. – June7 43 mins ago
Try this:
me.SetFocus
DoCmd.GoToRecord , , acNext

Recordset BOF/EOF cannot handle Nulls

I have a form and want to display a message when there are no records. The SQL in the following code displays no records (Null) (as it should at present). The function does not work as I wish. It neither returns a number nor displays the message. If I put the function in a form that does have records, it counts them accurately.
Public Function NumRecs() As Integer
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT tblClient.ClientName, tblInvoices.SentToPayer, [Adjustment]+[MyFee]+[DBSFee] AS TotFees, tblClient.ClientID, tblDisclosure.ApplicantForenames, tblDisclosure.AppEmail " & _
"FROM ((tblInvoiceDetails INNER JOIN tblDisclosure ON tblInvoiceDetails.DiscLookup = tblDisclosure.ID) INNER JOIN tblInvoices ON tblInvoiceDetails.InvoiceLookup = tblInvoices.ID) INNER JOIN ((tblOfficerDetails INNER JOIN tblOfficers ON tblOfficerDetails.OfficerLookup = tblOfficers.ID) INNER JOIN tblClient ON tblOfficerDetails.ClientLookup = tblClient.ClientID) ON tblInvoices.AppLookup = tblClient.ClientID " & _
"WHERE (((tblInvoices.DatePaid) Is Null)) ")
If Not rs.BOF And Not rs.EOF Then
NumRecs = Me.Recordset.RecordCount
Else
DisplayMessage ("No records.")
NumRecs = 0
End If
rs.Close
Set rs = Nothing
End Function
"I have a form and want to display a message when there are no records."
You can accomplish that task without opening another DAO.Recordset. Just use RecordsetClone, which already exists.
Private Sub Form_Load()
Dim lngRowCount As Long
lngRowCount = 0
With Me.RecordsetClone
If Not (.BOF And .EOF) Then
.MoveLast
lngRowCount = .RecordCount
End If
End With
MsgBox lngRowCount & " records"
End Sub
Whenever I need a record count in DAO I always MoveLast and then MoveFirst however
Dim db as DAO.Database
Dim rst as DAO.Recordset
Dim strSQL as string
strSQL = "" ' your query here
Set db=CurrentDB()
Set rst=db.OpenRecordset(stSQL,dbOpenDynaSet)
With rst
If NOT (.EOF and .BOF) Then ' There are records to be had
Dim iRecCount as Integer
.MoveLast: .MoveFirst
' DAO typically requires the all records before the count
' count is correct
iRecCount = .RecordCount
Else ' There are NOT records to be had
' ADD YOUR MESSAGE HERE FOR NO RECORDS.
End If
.Close
End with
Set rst=nothing
Set db=nothing
Optionally I build up my Queries external to VBA and add parameters. This why I know my query is producing the results I expect. Then you can reference your query as an object of QueryDefs of CurrentDB() object. Then address you parameters as a property of QueryDef.
The following is a great read from Allen Browne on Recordsets.
http://allenbrowne.com/ser-29.html
All you really need is:
Public Function NumRecs() As Integer
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
If rs.RecordCount = 0 Then
DisplayMessage ("No records.")
Else
rs.MoveLast
NumRecs = rs.RecordCount
End If
rs.Close
Set rs = Nothing
End Function
In order to get the recordcount with DAO, you need to MoveLast. Also, try changing the 'EOF' check (see below):
Public Function NumRecs() As Integer
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL as String
strSQL = "SELECT tblClient.ClientName, tblInvoices.SentToPayer, [Adjustment]+[MyFee]+[DBSFee] AS TotFees, tblClient.ClientID, tblDisclosure.ApplicantForenames, tblDisclosure.AppEmail " & _
"FROM ((tblInvoiceDetails INNER JOIN tblDisclosure ON tblInvoiceDetails.DiscLookup = tblDisclosure.ID) INNER JOIN tblInvoices ON tblInvoiceDetails.InvoiceLookup = tblInvoices.ID) INNER JOIN ((tblOfficerDetails INNER JOIN tblOfficers ON tblOfficerDetails.OfficerLookup = tblOfficers.ID) INNER JOIN tblClient ON tblOfficerDetails.ClientLookup = tblClient.ClientID) ON tblInvoices.AppLookup = tblClient.ClientID " & _
"WHERE (((tblInvoices.DatePaid) Is Null))"
Set dbs = CurrentDB
Set rs = dbs.OpenRecordset(strSQL)
If Not rs.EOF Then
rs.MoveLast ' ADD THIS LINE
NumRecs = rs.RecordCount
Else
DisplayMessage ("No records.")
NumRecs = 0
End If
rs.Close
Set rs = Nothing
dbs.Close
Set dbs = Nothing
End Function`

access 2010 vba recordset updates

New to Access VBA with extensive Informix SQL background. I have a recordset that includes record from 4 tables.
Based upon different situations, I want to update records in three of these tables with data from the fourth table.
I also want to add records to a comment table and output to reports. Can and how do I do this: Code follows:
Sub query_records_sql()
'Comments: Use the results of a SQL string and to update and add records as required
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSql As String
' Open pointer to current database
Set dbs = CurrentDb()
strSql = ""
'Create record set for tmp_peo records that have matches in main/prime/sub tables
strSql = " Select * FROM ((tmp_peo INNER JOIN tbl_prime ON (tmp_peo.prime = tbl_prime.prime)) " & _
" INNER JOIN tbl_sub ON (tmp_peo.sub = tbl_sub.sub)) " & _
" INNER JOIN tbl_main ON (tmp_peo.ship = tbl_main.ship_id) AND " & _
" (tbl_prime.prime_id = tbl_main.prime_id) AND (tbl_sub.sub_id = tbl_main.sub_id)"
' Create recordset based on SQL
Set rst = dbs.OpenRecordset(strSql)
Do While Not rst.EOF
If (tmp_peo.prime_nomenclature = tbl_prime.nomenclature) Then
If (tmp_peo.sub_nomenclature = tbl_sub_nomenclature) Then
If (((tmp_peo.quantity = tbl_main.quantity) Or (tmp_peo.quantity Is Null And tbl_main.quantity Is Null)) And
((tmp_peo.sked_a_mdb = tbl_main.sked_a_mbd) Or (tmp_peo.sked_a_mdb Is Null And tbl_main.sked_a_mdb Is Null)) And
((tmp_peo.swbs = tbl_main.swbs) Or (tmp_peo.swbs Is Null And tbl_main.swbs Is Null)) And
((tmp_peo.rdd_to_ptc = tbl_main.rdd_to_ptc) Or (tmp_peo.rdd_to_ptc Is Null And tbl_main.rdd_to_ptc Is Null)) And
((tmp_peo.ptc_bedd = tbl_main.ptc_bedd) Or (tmp_peo.ptc_bedd Is Null And tbl_main.ptc_bedd Is Null)) And
((tmp_peo.peo_ships_am_rdd = tbl_main.peo_ships_am_rdd) Or (tbl_peo.peo_ships_am_rdd Is Null And tbl_main.peo_ships_am_rdd Is Null)) And
((tmp_peo.sked_a_date = tbl_main.sked_a_date) Or (tbl_peo.sked_a_date Is Null And tbl_main.sked_a_date Is Null)) And
((tmp_peo.sypd = tbl_main.sypd) Or (tmp_peo.sypd Is Null And tbl_main.sypd Is Null)) And
((tmp_peo.parm_bedd_date = tbl_main.parm_bedd_date) Or (tmp_peo.par_bedd_date Is Null And tbl_main.parm_bedd_date Is Null)) And
((tmp_peo.yard_actual = tbl_main.yard_actual) Or (tmp_peo.yard_actual Is Null And tbl_main.yard.actual Is Null)) And
((tmp_peo.delivered_quantity = tbl_main.delivered_quantity) Or (tmp_peo.delivered_quantity Is Null And tbl_main.delivered_quantity Is Null)) And
((tmp_peo.shipment = tbl_main.shipment) Or (tmp_peo.shipment Is Null And tbl_main.shipment Is Null))) Then
' Output to 'No Update Required' Report
Else
' Update main with tmp_peo data
Call update_main
Call add_main_comment(tbl_main.main_id, "PRG", =DATE(), "MAIN RECORD UPDATED DURING WEEKLY PEO SKED A UPDATE PROCESS")
'Output to 'Main Record Updated' Report
End If
Else
'Update sub nomen with tmp_peo.sub_nomen
Call update_sub
Call add_main_comment(tbl_main.main_id, "PRG", =DATE(), "SUB RECORD UPDATED DURING WEEKLY PEO SKED A UPDATE PROCESS")
'Output to 'Sub Record Updated' report
End If
Else
'Update prime nomen with tmp_peo.prime_nomen
Call update_prime
Call add_main_comment(tbl_main.main_id, "PRG", =DATE(), "PRIME RECORD UPDATED DURING WEEKLY PEO SKED A UPDATE PROCESS")
'Output to "Prime Record Updated' report
End If
rst.MoveNext
Loop
'Close recordset
rst.Close
'Close Reports
'Open action required report
strSql = ""
'Create record set for tmp_peo records that have no matches in main/prime/sub tables
strSql = " Select tmp_peo.* WHERE tmp_peo.id Not In " & _
" (Select * FROM ((tmp_peo INNER JOIN tbl_prime ON (tmp_peo.prime = tbl_prime.prime)) " & _
" INNER JOIN tbl_sub ON (tmp_peo.sub = tbl_sub.sub)) " & _
" INNER JOIN tbl_main ON (tmp_peo.ship = tbl_main.ship_id) AND " & _
" (tbl_prime.prime_id = tbl_main.prime_id) AND (tbl_sub.sub_id = tbl_main.sub_id)"
dbs.Close
End Sub

In VBA, how does one make a table from a recordset

I have a recordset that I want to export into Excel 2000 format (acSpreadsheetTypeExcel9). I believe I need to drop it into a table first then execute a DoCmd.TransferSpreadsheet (keeps it easy and it works). The user sets just a few parameters in the form, thus the Me. syntax you will see.
Here's the working code so far:
Select Case Me.Controls("frame_ChooseReport").Value
Case 1
sExecuteQuery = "qry_PDSR w/ Destruct Dates"
bHasProgramCode = True
sFileName = "Project_Doc_Submittal_Request_better"
Case 2
sExecuteQuery = "qry_PDSR w/Destruct Dates BE"
bHasProgramCode = False 'This is the only query here that doesn't have a Program Code parameter
sFileName = "Project_Doc_Submittal_Request_better_BE"
Case 3
sExecuteQuery = "qry_Project Documentation Submittal Request w/ Destruct Dates"
bHasProgramCode = True
sFileName = "Project_Doc_Submittal_Request_ENH"
Case 4
sExecuteQuery = "qry_Project_Doc_Submittal_Request_w_Destruct_Dates_HES_Installer"
bHasProgramCode = True
sFileName = "Project_Doc_Submittal_Request_Installer"
Case Else
Stop 'Error! This should never be reached!
End Select
'Execute query & save output to Excel
Set qdf = CurrentDb.QueryDefs(sExecuteQuery) 'Open the query
'Assign values to the query using the parameters option
If bHasProgramCode = True Then
qdf.Parameters(0) = Me.lbl_ProgramCodes.Section
qdf.Parameters(1) = Me.txt_StartDate
qdf.Parameters(2) = Me.txt_EndDate
Else
qdf.Parameters(0) = Me.txt_StartDate
qdf.Parameters(1) = Me.txt_EndDate
End If
sFullPath = Me.lbl_SaveTo.Caption & "\" & sFileName
Set rst = qdf.OpenRecordset 'Convert the querydef to a recordset and run it
If rst.BOF = True And rst.EOF = True Then
MsgBox "No records were found.", vbExclamation, "Empty recordset"
Exit Sub
End If
'Dump recordset into a table, export it to Excel, then delete it.
'Here is where the recordset needs to become a table.
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_PDSR w/ Destruct Dates", sFullPath, True 'Export table to an Excel format
'Clean up!
DoCmd.DeleteObject acTable, gTEMP_TBL 'Done with the temporary table so delete it
rst.Close
qdf.Close
Set rst = Nothing
Set qdf = Nothing
Help/suggestions? Thank you.
Access 2010 in Windows 7
---------- FOLLOW UP ----------
Here's the query I added that will use the references of the opened form per Remou's suggestion:
SELECT dbo_PROJECT.PROJECTID, dbo_PROJECT.TITLE, dbo_PROJECT.PROGRAMCODE, dbo_PROJECT.PROJECTTYPE, dbo_PROJECT.REFERENCE, dbo_PROJECT.STATUS, dbo_PROJECT.PMC, dbo_TRANSACTION_SUM.STATUS, dbo_TRANSACTION_SUM.IMPORTEDDT, dbo_TRANSACTION_SUM.CHECKDT, dbo_PROJECT.NOTES, dbo_TRANSACTION_SUM.TRANSACTIONID, dbo_TRANSACTION_SUM.GL_ACCT, dbo_PROJECT_SUM.PAID_INCENT_TOTAL, dbo_TRANSACTION_SUM.AMOUNT
FROM ((dbo_INCENTIVE RIGHT JOIN dbo_PROJECT ON dbo_INCENTIVE.PROJECTID = dbo_PROJECT.PROJECTID) LEFT JOIN dbo_TRANSACTION_SUM ON dbo_INCENTIVE.INCENTIVEID = dbo_TRANSACTION_SUM.INCENTIVEID) LEFT JOIN dbo_PROJECT_SUM ON dbo_PROJECT.PROJECTID = dbo_PROJECT_SUM.PROJECTID
WHERE (((dbo_PROJECT.PROGRAMCODE) In ([Forms]![Submittal_Request_Report]![txt_ListProgramCodeSelections])) AND ((dbo_TRANSACTION_SUM.CHECKDT) Between [Forms]![Submittal_Request_Report]![txt_StartDate] And [Forms]![Submittal_Request_Report]![txt_EndDate]));
Here's the routine that is in the On_Exit event of the listbox:
Private Sub list_ProgramCodes_Exit(Cancel As Integer)
'Get selection from Program Code listbox and store it in a hidden textbox for the query.
Dim x As Long, sValue As String, ctlSource As Control
sValue = ""
Set ctlSource = Me!list_ProgramCodes
For x = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(x) Then
sValue = sValue & ctlSource.Column(0, x) & ","
End If
Next
Me.txt_ListProgramCodeSelections.Value = Left(sValue, Len(sValue) - 1) 'Drop the last comma
Set ctlSource = Nothing
End Sub
Works great! The SQL line In ([Forms]![Submittal_Request_Report]![txt_ListProgramCodeSelections]) pulls the list of items in the hidden textbox (using a label didn't work) that was populated with the selection from the listbox on the form.
This is now the code for exporting the query:
Private Sub btn_RunReport_Click()
Dim sExecuteQuery As String, sFullPath As String, sFileName As String
On Error GoTo Err_btn_RunReport_Click
If Left(Me.lbl_SaveTo.Caption, 4) = "save" Then
MsgBox "Please select a folder to save the results to.", vbInformation, "No folder selected"
Exit Sub
End If
Select Case Me.Controls("frame_ChooseReport").Value
Case 1
sExecuteQuery = "qry_PDSR_Destruct_Dates_form"
sFileName = "Project_Doc_Submittal_Request.xls"
Case 2
sExecuteQuery = "qry_Project_Doc_Submittal Request w/ Destruct Dates_form"
sFileName = "Project_Doc_Submittal_Request_ENH.xls"
Case 3
sExecuteQuery = "qry_PDSR_w_Destruct_Dates_HES_Installer_form"
sFileName = "Project_Doc_Submittal_Request_Installer.xls"
Case Else
Stop 'Error! This should never be reached!
End Select
sFullPath = Me.lbl_SaveTo.Caption & "\" & sFileName
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, sExecuteQuery, sFullPath, True 'Export table to an Excel format
Exit_btn_RunReport_Click:
Exit Sub
Err_btn_RunReport_Click:
MsgBox Err.Description
Resume Exit_btn_RunReport_Click
End Sub
Thanks Remou!
I suggest you just set the sql of a query to a suitable string and then export the query:
sSQL="SELECT * FROM Table WHERE Field=" & me.MyText
If IsNull(DLookup("name", "msysobjects", "name='query1'")) Then
CurrentDb.CreateQueryDef "Query1", sSQL
Else
CurrentDB.QueryDefs("Query1").SQL = sSQL
End If
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Query1", sFullPath
You can create a query that references an open form:
SELECT Test.ID, Test.Data
FROM Test
WHERE Test.AField=[forms]![test]![pickone]