This is probably so simple for someone out there, but I have spent a lot of time on it. I am trying to set a variable to the value of the single field in a one line table. I get an Object Required message. I have reviewed many posts, etc., but can't figure out what I am doing wrong. Any help would be greatly appreciated!
Code here:
Option Compare Database
Function Macro1()
'On Error GoTo Macro1_Err
Dim strTOP1 As String
Dim DBS As Database
Set DBS = CurrentDb
DoCmd.OpenQuery "qMT_OAC_PARTS", acViewNormal, acEdit
'Do Until ISNULL strTOP1
DoCmd.OpenQuery "qMT_TOP1", acViewNormal, acEdit '(Generates one value, TOP1)
strTOP1 = TABLES![TOP1].[MK].Value '(Error occurs here)
DoCmd.OpenQuery "qMT_OAC_PARTS2", acViewNormal, acEdit
'DoCmd.TransferSpreadsheet acExport, 8, "OAC_PARTS2", "P:\Development\zLinkedFiles\XXXXXXX\REPORTS\REPORT.XLS", False, "strTOP1!A1:Z65536"
DoCmd.OpenQuery "qDEL_OAC_VALID", acViewNormal, acEdit
'Loop
Macro1_Exit:
Exit Function
Macro1_Err:
MsgBox Error$
Resume Macro1_Exit
End Function
Eventually I will have the results of the 2nd query export to Excel, and then loop until the original file is exhausted. Right now, I need to fix this problem.
Thanks for looking at this!
Code here:
Option Compare Database
Function Macro1()
'On Error GoTo Macro1_Err
Dim strTOP1 As String
Dim DBS As Database
Set DBS = CurrentDb
DoCmd.OpenQuery "qMT_OAC_PARTS", acViewNormal, acEdit
'Do Until ISNULL strTOP1
DoCmd.OpenQuery "qMT_TOP1", acViewNormal, acEdit '(Generates one value, TOP1)
strTOP1 = TABLES![TOP1].[MK].Value '(Error occurs here)
DoCmd.OpenQuery "qMT_OAC_PARTS2", acViewNormal, acEdit
'DoCmd.TransferSpreadsheet acExport, 8, "OAC_PARTS2", "P:\Development\zLinkedFiles\XXXXXXX\REPORTS\REPORT.XLS", False, "strTOP1!A1:Z65536"
DoCmd.OpenQuery "qDEL_OAC_VALID", acViewNormal, acEdit
'Loop
Macro1_Exit:
Exit Function
Macro1_Err:
MsgBox Error$
Resume Macro1_Exit
End Function
Eventually I will have the results of the 2nd query export to Excel, and then loop until the original file is exhausted. Right now, I need to fix this problem.
Thanks for looking at this!