I have inherited a database with VBA and it is coming up with an error message I can not fix. I'm hoping someone will be able to help me. I'm getting a 'Type Mismatch' error at the 'Set rsSC' line. I'm not sure what information you need to help fix it. Thank you -Sharon
Public Function getSO()
DoCmd.SetWarnings False
Dim strSQL As String, strORG As String
Dim intDEPT As Integer, intCLASS As Integer, intSCLASS As Integer
Dim rsSC As Recordset
Dim rsORG As Recordset
Set rsSC = CurrentDb.OpenRecordset("tblSC")
Set rsORG = CurrentDb.OpenRecordset("tblStoreOrg")
DoCmd.RunSQL ("DELETE * FROM tblMDC_SO;")
With rsORG
.MoveFirst
Do Until .EOF
strORG = ![STR_TXT]
With rsSC
.MoveFirst
Do Until .EOF
lngDEPT = ![MER_DEPT_NBR]
lngCLASS = ![MER_CLASS_NBR]
lngSCLASS = ![MER_SUB_CLASS_NBR]
strSQL = "INSERT INTO tblMDC_SO "
strSQL = strSQL & "( CRT_TS, STR_NBR"
strSQL = strSQL & ", MER_DEPT_NBR, MER_CLASS_NBR"
strSQL = strSQL & ", MER_SUB_CLASS_NBR, ORD_QTY"
strSQL = strSQL & ", ORD_COST_AMT, ORD_RETL_AMT"
strSQL = strSQL & ", CUST_ORD_NBR ) "
strSQL = strSQL & "SELECT PRHDW_SO_MER.CRT_TS"
strSQL = strSQL & ", PRHDW_SO_MER.STR_NBR"
strSQL = strSQL & ", PRHDW_SO_MER.MER_DEPT_NBR"
strSQL = strSQL & ", PRHDW_SO_MER.MER_CLASS_NBR"
strSQL = strSQL & ", PRHDW_SO_MER.MER_SUB_CLASS_NBR"
strSQL = strSQL & ", PRHDW_SO_MER.ORD_QTY"
strSQL = strSQL & ", PRHDW_SO_MER.ORD_COST_AMT"
strSQL = strSQL & ", PRHDW_SO_MER.ORD_RETL_AMT"
strSQL = strSQL & ", PRHDW_SO_MER.CUST_ORD_NBR"
strSQL = strSQL & "FROM PRHDW_SO_MER "
strSQL = strSQL & "WHERE PRHDW_SO_MER.STR_NBR='" & strORG & "' "
strSQL = strSQL & "AND PRHDW_SO_MER.MER_DEPT_NBR=" & lngDEPT & " "
strSQL = strSQL & "AND PRHDW_SO_MER.MER_CLASS_NBR=" & lngCLASS & " "
strSQL = strSQL & "AND PRHDW_SO_MER.MER_SUB_CLASS_NBR=" & lngSCLASS & ";"
Debug.Print ("'" & strORG & "' & " & lngDEPT & " & " & lngCLASS & " & " & lngSCLASS & "")
DoCmd.RunSQL strSQL
.MoveNext
Loop
End With
.MoveNext
Loop
End With
rsORG.Close
rsSC.Close
DoCmd.SetWarnings True
End Function
Public Function getSO()
DoCmd.SetWarnings False
Dim strSQL As String, strORG As String
Dim intDEPT As Integer, intCLASS As Integer, intSCLASS As Integer
Dim rsSC As Recordset
Dim rsORG As Recordset
Set rsSC = CurrentDb.OpenRecordset("tblSC")
Set rsORG = CurrentDb.OpenRecordset("tblStoreOrg")
DoCmd.RunSQL ("DELETE * FROM tblMDC_SO;")
With rsORG
.MoveFirst
Do Until .EOF
strORG = ![STR_TXT]
With rsSC
.MoveFirst
Do Until .EOF
lngDEPT = ![MER_DEPT_NBR]
lngCLASS = ![MER_CLASS_NBR]
lngSCLASS = ![MER_SUB_CLASS_NBR]
strSQL = "INSERT INTO tblMDC_SO "
strSQL = strSQL & "( CRT_TS, STR_NBR"
strSQL = strSQL & ", MER_DEPT_NBR, MER_CLASS_NBR"
strSQL = strSQL & ", MER_SUB_CLASS_NBR, ORD_QTY"
strSQL = strSQL & ", ORD_COST_AMT, ORD_RETL_AMT"
strSQL = strSQL & ", CUST_ORD_NBR ) "
strSQL = strSQL & "SELECT PRHDW_SO_MER.CRT_TS"
strSQL = strSQL & ", PRHDW_SO_MER.STR_NBR"
strSQL = strSQL & ", PRHDW_SO_MER.MER_DEPT_NBR"
strSQL = strSQL & ", PRHDW_SO_MER.MER_CLASS_NBR"
strSQL = strSQL & ", PRHDW_SO_MER.MER_SUB_CLASS_NBR"
strSQL = strSQL & ", PRHDW_SO_MER.ORD_QTY"
strSQL = strSQL & ", PRHDW_SO_MER.ORD_COST_AMT"
strSQL = strSQL & ", PRHDW_SO_MER.ORD_RETL_AMT"
strSQL = strSQL & ", PRHDW_SO_MER.CUST_ORD_NBR"
strSQL = strSQL & "FROM PRHDW_SO_MER "
strSQL = strSQL & "WHERE PRHDW_SO_MER.STR_NBR='" & strORG & "' "
strSQL = strSQL & "AND PRHDW_SO_MER.MER_DEPT_NBR=" & lngDEPT & " "
strSQL = strSQL & "AND PRHDW_SO_MER.MER_CLASS_NBR=" & lngCLASS & " "
strSQL = strSQL & "AND PRHDW_SO_MER.MER_SUB_CLASS_NBR=" & lngSCLASS & ";"
Debug.Print ("'" & strORG & "' & " & lngDEPT & " & " & lngCLASS & " & " & lngSCLASS & "")
DoCmd.RunSQL strSQL
.MoveNext
Loop
End With
.MoveNext
Loop
End With
rsORG.Close
rsSC.Close
DoCmd.SetWarnings True
End Function